백준 10250번: ACM 호텔

danbibibi·2021년 9월 18일
0

문제

문제 바로가기> 백준 10250번: ACM 호텔

풀이

import math
T = int(input())
for i in range(T):
    H, W, N = map(int, input().split())
    if N%H:
        floor = N%H
    else:
        floor = H
    arc = math.ceil(N/H)
    if arc//10:
        print(str(floor)+str(arc))
    else:
        print(str(floor)+'0'+str(arc))

코드개선

if arc//10:
    print(str(floor)+str(arc))
else:
    print(str(floor)+'0'+str(arc))
    
#아래와 같이 짧게 작성할 수 있다. 
print("%d%02d" % (floor, arc))
# or 
print('{0}{1:02d}'.format(floor, arc))

N자리로 포맷팅
정수부 : 0Nd
실수부 : 0.Nf

H, W, N = map(int, input().split())

#아래와 같은 방법으로 더 빠르게 입력 받을 수 있음 
H, W, N = map(int, sys.stdin.readline().split())
import sys
a = sys.stdin.readline()

python에서 input()보다 빠르게 입력을 받는 방법으로는 sys.stdin.readline()을 사용하면 되는데, 이때 맨 끝의 줄바꿈 문자(\n)까지 입력이 된다.

a = sys.stdin.readline().rstrip()

줄바꿈 문자는 제외하고 입력받고 싶으면 뒤에 .rstrip()을 붙이면 된다.

profile
블로그 이전) https://danbibibi.tistory.com

0개의 댓글

관련 채용 정보