728x90
6812번: Good times
A mobile cell service provider in Ottawa broadcasts an automated time standard to its mobile users that reflects the local time at the user’s actual location in Canada. This ensures that text messages have a valid local time attached to them. For example
www.acmicpc.net
문제 풀이
이 문제는 주어진 입력값으로 각각의 지역 시간대로 변환해 출력해야하는 문제이다. 이 문제에서 주의할 점은 다음과 같다.
- 입력값은 0부터 2359사이의 수이다. (ex. 0을 입력받으면 00시 00분이 된다.)
- 출력할 때, 불필요한 0이 있으면 안된다. (ex. 0030 (x) -> 30 (o))
- 0 이하일 때는 24시간을 더해준다.
- St. John's는 30분을 더해줘야하므로 특별히 주의하자 (ex. 2330을 입력해보자)
정답 코드
코드가 깔끔하지 못한게 좀 아쉽다.
ot = input()
while len(ot) != 4 :
ot = "0" + ot
print(int(ot), "in Ottawa")
ot_hour, ot_min = ot[:2], ot[2:]
if int(ot_hour) - 3 < 0 : print(int(str(int(ot_hour) - 3 + 24) + ot_min), "in Victoria")
else : print(int(str(int(ot_hour) - 3) + ot_min), "in Victoria")
if int(ot_hour) - 2 < 0 : print(int(str(int(ot_hour) - 2 + 24) + ot_min), "in Edmonton")
else : print(int(str(int(ot_hour) - 2) + ot_min), "in Edmonton")
if int(ot_hour) - 1 < 0 : print(int(str(int(ot_hour) - 1 + 24) + ot_min), "in Winnipeg")
else : print(int(str(int(ot_hour) - 1) + ot_min), "in Winnipeg")
print(int(ot), "in Toronto")
if int(ot_hour) + 1 == 24 : print(int(ot_min), "in Halifax")
else : print(int(str(int(ot_hour) + 1) + ot_min), "in Halifax")
st_min = int(ot_min) + 30
if st_min >= 60 :
st_hour = str(int(ot_hour) + 2)
st_min -= 60
else : st_hour = str(int(ot_hour) + 1)
if st_min == 0 and st_hour != 0 : st_min = "00"
else : st_min = str(st_min)
if int(st_hour) > 23 : st_hour = str(int(st_hour) - 24)
print(int(st_hour + st_min), "in St. John's")
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 6845 - Federal Voting Age [python] (0) | 2023.03.19 |
---|---|
[BOJ/백준] 6830 - It’s Cold Here! [python] (0) | 2023.03.19 |
[BOJ/백준] 6794 - What is n, Daddy? [python] (0) | 2023.03.19 |
[BOJ/백준] 6784 - Multiple Choice [python] (0) | 2023.03.19 |
[BOJ/백준] 6780 - Sumac Sequences [python] (0) | 2023.03.19 |