BEAKJOON
백준(10250번 ACM 호텔)풀이 C++
Shin_jisoo
2021. 1. 12. 21:59
728x90
10250번: ACM 호텔
프로그램은 표준 입력에서 입력 데이터를 받는다. 프로그램의 입력은 T 개의 테스트 데이터로 이루어져 있는데 T 는 입력의 맨 첫 줄에 주어진다. 각 테스트 데이터는 한 행으로서 H, W, N, 세 정수
www.acmicpc.net
1) 주석 없는 VERSION
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
int t;
cin >> t;
int h, w, n;
int x, y;
int room_h = 0;
int room_w = 0;
while(t--) {
cin >> h >> w >> n;
room_h = n % h;
room_w = n / h + 1;
if (room_h == 0) {
room_h = h;
}
if (!(n % h)) {
room_w -= 1;
}
cout << room_h * 100 + room_w << endl;
}
}
2) 주석 있는 VERSION
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
int t;
cin >> t;
int h, w, n;
int x, y;
int room_h = 0; // 해당 층수
int room_w = 0; // 해당 호수
while(t--) {
cin >> h >> w >> n;
room_h = n % h; // 몇 번째 행인지는 높이로 나눈 나머지로 계산
room_w = n / h + 1; // 몇 번째 열인지는 높이로 나눈 몫에 +1
if (room_h == 0) {
room_h = h; // 나누어 떨어질 경우에는 꼭대기 층이기 때문에
}
if (!(n % h)) {
room_w -= 1; // 나누어 떨어질 경우에는 +1을 해주면 안되기 때문에
}
cout << room_h * 100 + room_w << endl;
}
}