날짜 데이터 비교하기
https://codeup.kr/problem.php?id=4713&rid=0
def date_to_num(date): # month date -> int(month+day) (e.g. 1 1 -> 101)
start = int(date[0]+'0'+date[1]) if len(date[1]) == 1 else int(date[0]+date[1])
end = int(date[2]+'0'+date[3]) if len(date[3]) == 1 else int(date[2]+date[3])
return start,end
# input
N = int(input())
date_list = []
for _ in range(N):
num = date_to_num(input().split())
date_list.append(tuple(num if num[1] > 301 else [1231,1231]))
date_list = sorted(list(set(date_list)))
# cnt : # flowers, start : the first date where another flower is needed, end: the last date of the flower
cnt, start,end = 0, 301,0
condition = True
while condition: # while stops when we have avaliable flowers from 301~1130 or there is no available flower anymore.
# fl_list : list of flowers blooming before 'start'
fl_list = []
for i,dl in enumerate(date_list):
if (dl[0] <= min(start,1130)):
fl_list.append(dl)
end = max(end,dl[1]) # we finally select the flower which will bloom the longest
else:
i -= 1
break
# pick the flower
if fl_list:
cnt += 1
date_list = [] if i == len(date_list) -1 else date_list[i+1:]
start = end
if start > 1130:
print(cnt)
condition = False
else:
print(0)
condition = False
Time cost를 줄여보자!
1. cnt 사용하지 말 것
1-1. lend(fl_list)으로 출력
2. for i in range(x, N)를 사용해 볼 것
=> datetime을 활용하되, 전체 구조는 22년도 코드 구조를 진행해보는 것이 좋을 듯.