코딩테스트/코딩테스트 연습
[C++] 프로그래머스 2018 KAKAO BLIND RECRUITMENT [1차] 추석 트래픽
Bradbury
2020. 10. 28. 09:25
728x90
(2시간)
sstream헤더를 이용한 문자열 처리, 변수 타입 변환 등은 확실히 알고 있기.
stringstream과 istringstream을 활용한 문자열 처리가 strtok를 사용한 방식보다 확실히 편한것 같다.
#include <string>
#include <cstring>
#include <vector>
#include <sstream>
using namespace std;
int solution(vector<string> lines) {
int max_count = 0;
vector<pair<double, double>> timeline;
for (int i = 0; i < lines.size(); i++) {
vector<string> log;
stringstream ss(lines[i]);
string token;
while((ss >> token)) {
log.push_back(token);
}
istringstream iss(log[1]);
double total = 0;
int mul = 3600;
while (getline(iss, token, ':')) {
total += atof(token.c_str()) * mul;
mul /= 60;
}
double t = atof(log[2].substr(0, log[2].size() - 1).c_str());
double start = total - t + 0.001;
timeline.push_back(make_pair(start, total));
}
for(int i = 0; i < timeline.size(); i++){
int count = 1;
double end = timeline[i].second;
for(int j = i + 1; j < timeline.size(); j++){
if(timeline[j].first < end + 1) count++;
}
if(max_count < count) max_count = count;
}
return max_count;
}
728x90