반응형
Notice
Recent Posts
Recent Comments
Link
동캄의 코딩도장
프로그래머스 level3 [추석 트래픽] 파이썬 본문
반응형
https://programmers.co.kr/learn/courses/30/lessons/17676
코딩테스트 연습 - [1차] 추석 트래픽
입력: [ "2016-09-15 20:59:57.421 0.351s", "2016-09-15 20:59:58.233 1.181s", "2016-09-15 20:59:58.299 0.8s", "2016-09-15 20:59:58.688 1.041s", "2016-09-15 20:59:59.591 1.412s", "2016-09-15 21:00:00.464 1.466s", "2016-09-15 21:00:00.741 1.581s", "2016-09-1
programmers.co.kr
#프로그래머스 추석 트래픽
def solution(lines):
answer = 0
time=[]
for line in lines:
f,s,spend=map(str,line.split())
hour,min,sec=map(str,s.split(':'))
sec,msec=sec.split('.')
spend=float(spend[:-1])
S=int(hour)*3600+int(min)*60+int(sec)+float(msec)*(0.001)
if S-spend+0.001<0:
start=0.0
else:
start=S-spend+0.001
time.append([start,S])
for i in range(len(time)):
ans=1
cri=time[i][1]+1
j=i+1
while j<len(time):
if cri>time[j][0]:
ans+=1
j+=1
answer=max(ans,answer)
return answer
현재 시간을 초로 변환한다(종료점). 이후, 각 시간을 기준으로 시작점을 구하고, 시작점과 종료점을 배열에 담는다. 배열의 값을 하나씩 꺼내면서, 종료점보다 작은 시작점이 몇개나 있는지 확인한다.
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [이진 변환 반복하기] 파이썬 (0) | 2021.12.06 |
---|---|
프로그래머스 level2 [점프와 순간 이동] 파이썬 (0) | 2021.12.06 |
프로그래머스 level2 [멀쩡한 사각형] 파이썬 (0) | 2021.12.02 |
프로그래머스 level2 [압축] 파이썬 (0) | 2021.12.02 |
프로그래머스 level2 [다음 큰 숫자] 파이썬 (0) | 2021.12.02 |