[Programmers] 추석 트래픽

Time Lapse :1hour 0min 0sec

solution.cpp

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

vector<pair<double,double>> list;

void anal(vector<string> lines){
for(int i=0;i<lines.size();i++){
string times;
long double t = ((lines[i][11]-'0')*10+(lines[i][12]-'0'))*3600;
long double m = ((lines[i][14]-'0')*10+(lines[i][15]-'0'))*60;
long double s = ((lines[i][17]-'0')*10+(lines[i][18]-'0'));
long double u = ((double)(lines[i][20]-'0')/10) +
((double)(lines[i][21]-'0')/100) +
((double)(lines[i][22]-'0')/1000);
long double end_time = t+m+s+u;
for(int j=24;j<=lines[i].length()-2;j++)
times.push_back(lines[i][j]);
long double start_time = end_time - stod(times) + 0.001;
list.push_back(make_pair(start_time,end_time));
}
}
int solution(vector<string> lines) {
if(lines.size()==0)
return 0;
else if(lines.size()==1)
return 1;
anal(lines);
int answer = 0;
for(int i=0;i<list.size();i++){
int cnt = 0;
long double comp_start = list[i].second;
long double comp_end = comp_start+0.9995;
cout.precision(11);
for(int j=0;j<list.size();j++){
if(comp_start<=list[j].second && list[j].second<=comp_end){
cnt++;
}
else if(comp_start<=list[j].first && list[j].first<=comp_end){
cnt++;
}
else if(list[j].first<=comp_start&&comp_end<=list[j].second)
cnt++;

}
answer = max(answer,cnt);
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/thanksGivingTraffic/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.