PS/BOJ
[백준]ACM 호텔
RUBY_루비
2024. 2. 18. 23:00
출처:: https://www.acmicpc.net/problem/10250
분류:: 브루트포스
1. 문제 이해 및 해결과정
h=10, w=12 1) n= 110, 1011호 (110 - 1) % 10 + 1 = 10 (110 - 1) / 10 + 1 = 11 2) n=111, 112호 (111 - 1) % 10 + 1 = 10 (111 - 1) / 10 + 1 = 11 => floor ((n-1)%h) +1 // [1,h] => distance (n-1) / h + 1 //[1,w] |
2. 풀이방법
1) python
t = int(input())
for _ in range(t):
h, w, n = map(int, input().split())
floor = (n-1)% h +1
num = (n-1)//h + 1
print(floor * 100 + num)
2) c++
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h, w,n,cnt=0,testcase;
cin >> testcase;
while (testcase--) {
cin >> h >> w >> n;
cnt = 0;
for (int i = 1; i <=w; i++) {
for (int j = 1; j <= h; j++) {
cnt++;
//cout << i <<" "<<j<<endl;
if (cnt == n) {
if (i < 10) {
cout << j << "0" << i << endl;
}
else {
cout << j << i << endl;
}
}
}
}
}
return 0;
}
3. 오답원인
4. 알게된 점