[백준] 10250. ACM 호텔

원숭2·2022년 2월 3일
0

백준

목록 보기
25/54

문제

풀이

  1. 호텔의 방 배정은 i라인 객실을 전부 채운 후, i+1을 채우는 방식으로 진행 됨.
  2. 층수는 사람 수(p) % 층(h)로 계산하면 되지만, p == h인 경우에 0이 나오는 오류가 생김.
  3. 위 경우를 해결하기 위해 p % h == 0 일 경우, h = n으로 바꿔줌.
  4. 호수는 사람 수(p) / 층(h) 의 올림 값과 같음.

코드

import math

time = int(input())

def hotel(t) :
    for i in range(t) :
        h, w, p = map(int, input().split())
        
        if h == 1 :
            head = str(1)
        elif (p % h) == 0 :
            head = str(h)
        else :
            head = str(p % h)
        tail = str(math.ceil(p / h))
        if len(tail) == 1 :
            tail = '0' + tail
        print(int(head + tail))


hotel(time)

0개의 댓글