Created
June 8, 2020 04:52
-
-
Save DongguemYoo/4fa83776d9a06669e4f53d1ddf4252a0 to your computer and use it in GitHub Desktop.
[코딩테스트] 추석 트래픽.python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 검색한것 | |
// s.split(" ") 문자열 s를 공백 기준으로 나누기 | |
// s.replace("s","") 문자열 s를 공백으로 대체하기 | |
// float(s) string을 float로 변경하기 | |
// dic사용하기 dic ={} | |
// dic<int,list> | |
// value =[] | |
//dic[index] = value | |
//datetime 초로 변환하기 | |
// | |
// DT = datetime.datetime.strptime(time[0] +" "+ time[1], '%Y-%m-%d %H:%M:%S.%f') | |
///정답 | |
import datetime, time | |
# 받은 라인을 dic<int,list>에 저장하기 | |
# list[0]은 시작시간 | |
# list[1]은 끝시간 | |
def time_to_second(lines): | |
dic = {} | |
DT = datetime.datetime.today() | |
startTime = 0.0 | |
secondfirst = 0.0 | |
secondLast = "" | |
index = 0 | |
i = 0 | |
for index in range(0, len(lines)): | |
time = lines[index].split(" ") | |
for i in range(0, len(time)): | |
if i == 1: | |
secondfirst = time[i].split(":") | |
if i == 2: | |
secondLast = time[i].replace("s", "") | |
sec = secondfirst[2].split('.') | |
DT = datetime.datetime.strptime(time[0] +" "+ time[1], '%Y-%m-%d %H:%M:%S.%f') | |
secondfirst = DT.timestamp() | |
startTime = secondfirst - float(secondLast) + 0.001 | |
value = [] | |
value.append(round(startTime, 3)) | |
value.append(round(secondfirst, 3)) | |
dic[index] = value | |
return dic | |
def solution(lines): | |
answer = 0 | |
dic =time_to_second(lines) | |
tmpcount =0 | |
for x in dic: | |
dicIndex =x | |
tmpcount=1 | |
#시간은 순차적으로 쌓이니까 | |
#마지막시간 + 1초가 다음 시간의 시작시간과 겹친다면 1초에 처리할수있는 수가 여러개이다 | |
for dicIndex in range(x+1,len(dic)): | |
if(dic[x][1]+float(1) > dic[dicIndex][0]): | |
tmpcount+=1 | |
if tmpcount>answer: | |
answer = tmpcount | |
if answer ==0: | |
return 1 | |
return answer | |
lines = ["2016-09-15 01:00:04.002 2.0s", | |
"2016-09-15 01:00:07.000 2s"] | |
# lines =["2016-09-15 01:00:04.001 2.0s", "2016-09-15 01:00:07.000 2s"] | |
print(solution(lines)) | |
//다른사람풀이 | |
너무 다양하다. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment