https://www.acmicpc.net/problem/2852
[English Translation]
Donghyuk enjoys watching NBA basketball games. Donghyuk has this weird hobby, where a team scores a goal, he records the time the goal got in and the team who scored. Basketball game goes on for 48 minutes. Return the time how long each team was winning.
[Input]
In the first line, total count of that each goal is given.
Starting from the second line , n lines of scoring informations are given. The team number is 1 or 2. The time scored is in MM:SS (Minute, Second) Format, if minute and second is one digit, the first digit is 0. Minute is bigger than or equal to 0, and less than or equal to 47. Second is bigger than or equal to 0, and smaller than or equal to 59. There is no case where scoring time that overlaps.
[Output]
In the first line, return the total amount of time first team was winning.
In the second line, return the total amount of time second team was winning.
Time is returned as a same format of the input.
생각보다 까다로우면서, 정말 재미있게 풀었던 구현 문제이다.
score는 1팀이 점수를 냈으면, +1을, 2팀이 점수를 냈으면 -1을 하였다.
즉 score가 2면 1팀과 2팀의 점수차가 1팀의 2점차 리드, score가 0이면 1팀과 2팀의 점수가 동률이라고 정의할 수 있다.
48분동안 1팀이 이기고 있는 시간, 2팀이 이기고 있는 시간을 정의하기 위해, 각각 onewinning, twowinning이라는 변수를 정의하였는데, 통일성을 위해서 모두 초로 저장하였다. 초로 저장하기 위해서, 분은 60을 곱하여 초로 만들었고, 분 옆의 초를 더하여 총 몇 초인지 구하였다.
n=int(input())
score=0 #if positive, 1 is winning
onewinning=0
twowinning=0
lasttime=0
for _ in range(n):
team,time=input().split()
minute,second=map(int,time.split(":"))
currenttime=minute*60+second
if score>0:
onewinning+=currenttime-lasttime
elif score<0:
twowinning+=currenttime-lasttime
if team=='1':
score+=1
else:
score-=1
lasttime=currenttime
if score>0:
onewinning+=48*60-lasttime
elif score<0:
twowinning+=48*60-lasttime
print("%02d:%02d" %(onewinning//60,onewinning%60))
print("%02d:%02d" %(twowinning//60,twowinning%60))
마지막에 48분에 경기가 끝나기 때문에, 마지막 점수부터 48분까지 점수를 낸 시간까지 리드한 팀의 시간을 추가하여 구현했다.
'Computer Science > Algorithm' 카테고리의 다른 글
[Python 3] BOJ 11375: 열혈강호 (0) | 2025.01.06 |
---|---|
[Python 3] BOJ 11967 불켜기 (0) | 2024.12.30 |
[C++] BOJ 11066 파일 합치기 (1) | 2024.10.13 |
[C++] BOJ 18235 지금 만나러 갑니다 (배열의 초기화 정리) (6) | 2024.10.11 |
[Python 3] BOJ 12931 두 배 더하기 (0) | 2024.10.07 |