2018 KAKAO BLIND RECRUITMENT (2018 카카오 블라인드 채용 문제)
1초에 가장 많은 처리를 한 횟수를 구하는 문제입니다.
끝나는 시간을 기준으로 정렬합니다.
기준시간의 끝나는 시간 + 1초보다 (기준시간 + i)시간의 시작 시간이 더 작으면 카운트합니다.
모든 시간을 기준으로 위의 작업을 해준 다음 카운트의 개수가 가장 큰 값을 출력해줍니다.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
vector<string> split(string str, char Delimiter) {
istringstream iss(str);
string buffer;
vector<string> result;
while (getline(iss, buffer, Delimiter)) {
result.push_back(buffer);
}
return result;
}
int convert(string s, string minus)
{
int num = 0;
minus = minus.substr(0, minus.length()-1);
if(minus.length() == 1){
minus += ".";
}
while(minus.length() != 5){
minus += "0";
}
vector<string> c;
c = split(s, ':');
num += 3000;
num += stod(c[2]) * 1000;
num += stod(c[1]) * 60 * 1000;
num += stod(c[0]) * 3600 * 1000;
num -= stod(minus) * 1000;
return num;
}
int solution(vector<string> lines) {
int answer = 0;
int a, b;
int count;
int result = 0;
int start, end;
int compStart, compEnd;
vector<pair<int, int> > v;
vector<string> temp;
for(int i=0; i<lines.size(); ++i){
temp = split(lines[i], ' ');
a = convert(temp[1], "0s");
b = convert(temp[1], temp[2]);
v.push_back({a, b});
}
sort(v.begin(), v.end());
for(int i=0; i<v.size(); ++i){
start = v[i].second;
end = v[i].first;
count = 1;
for(int j=i+1; j<v.size(); ++j){
compStart = v[j].second;
compEnd = v[j].first;
if(end + 1000 - 1 > compStart){
++count;
}
}
result = max(result, count);
}
return result;
}
'알고리즘' 카테고리의 다른 글
[C++] 프로그래머스 - 셔틀버스 (0) | 2021.09.14 |
---|---|
[C++] 프로그래머스 - 거리두기 확인하기 (0) | 2021.09.14 |
[JavaScript] 프로그래머스 - 키패드 누르기 (0) | 2021.09.14 |
[JavaScript] 프로그래머스 - 직업군 추천하기 (0) | 2021.08.28 |
[C++] 11779번 최소비용 구하기 2 (0) | 2021.08.28 |