
과정
- 골을 넣은 팀과 골이 들어간 시간이 입력으로 주어진다.
- 전체 경기 시간 중, 각 팀이 이기고 있던 시간을 출력한다.
- 입력이 들어오면, 그 순간의 점수를 확인한다.
- 그 때까지 걸린 시간을 이기고 있는 팀에 추가
- 시작 시간 초기화
- 시각은 초 단위로 계산하기
import sys
N = int(input())
start = 0
one_score = 0
two_score = 0
one_time = 0
two_time = 0
winning = 0
def add_time(before_time, after_time):
return after_time - before_time
def time_to_sec(min_sec):
min = int(min_sec[:2])
sec = int(min_sec[3:])
return min * 60 + sec
def time_to_min_str(sec):
min = sec // 60
sec = sec % 60
if min == 0:
str_min = "00"
elif min < 10:
str_min = "0" + str(min)
else:
str_min = str(min)
if sec == 0:
str_sec = "00"
elif sec < 10:
str_sec = "0" + str(sec)
else:
str_sec = str(sec)
return str_min + ":" + str_sec
# print(time_to_sec(inp_lst[1]))
for _ in range(N):
inp_lst = list(input().split())
team = inp_lst[0]
# 팀 점수 더하기
if team == "1":
one_score += 1
else:
two_score += 1
# 이기고 있던 시간 반영
if winning == 1:
one_time += add_time(start, time_to_sec(inp_lst[1]))
elif winning == 2:
two_time += add_time(start, time_to_sec(inp_lst[1]))
# 앞으로 이기고 있게 될 팀 반영, 시작 시간 초기화
if one_score > two_score:
winning = 1
start = time_to_sec(inp_lst[1])
elif one_score < two_score:
winning = 2
start = time_to_sec(inp_lst[1])
else:
winning = 0
# 마지막까지 이기고 있는 팀 시간 반영
if winning == 1:
one_time += add_time(start, time_to_sec("48:00"))
elif winning == 2:
two_time += add_time(start, time_to_sec("48:00"))
print(time_to_min_str(one_time))
print(time_to_min_str(two_time))