Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- level0
- level2
- 구현
- 딕셔너리
- dfs
- programmers
- 백준
- 그리디
- level3
- 프로그래머스
- BFS
- DP
- 운영체제
- 다이나믹 프로그래밍
- 스택
- 코딩테스트
- python
- 수학
- dict
- level1
- 재귀
- BOJ
- 브루트포스
- 가상메모리
- 힙
- 가상메모리 관리
- MYSQL
- 다익스트라
- 파이썬
- N과M
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 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 |