반응형
https://programmers.co.kr/learn/courses/30/lessons/17676
시간을 초로 바꾸기
로그의 시작과 끝에 대해서만 탐색 수행하기
#include<iostream>
#include <string>
#include <vector>
using namespace std;
int finds, finde;
int solution(vector<string> lines) {
int size = lines.size();
vector<pair<int, int> > time;
for (int i = 0; i < size; i++)
{
int blanck = 0;
string complete = "";
string second = "";
for (int j = 0; j < lines[i].size(); j++)
{
if (lines[i][j] == ' ')
{
blanck++;
}
else if (blanck == 1 && lines[i][j] >= '0' && lines[i][j] <= '9')
{
complete += lines[i][j];
}
else if (blanck == 2 && lines[i][j] >= '0' && lines[i][j] <= '9')
{
second += lines[i][j];
}
}
while (second.size() != 4)
{
second += '0';
}
int end = 0;
int start = 0;
int temp = 0;
int idx = 1;
for (int j = second.size() - 1; j >= 0; j--)
{
temp += (second[j] - '0') * idx;
idx *= 10;
}
end += (complete[0] - '0') * 10 * 3600;
end += (complete[1] - '0') * 3600;
end += (complete[2] - '0') * 600;
end += (complete[3] - '0') * 60;
end += (complete[4] - '0') * 10;
end += (complete[5] - '0');
end *= 1000;
end += (complete[6] - '0') * 100;
end += (complete[7] - '0') * 10;
end += (complete[8] - '0') * 1;
start = end - temp + 1;
time.push_back({ start,end });
}
int c = 0;
bool flag = false;
finds = time[0].first - time[0].first % 1000;
finde = finds + 1000 - 1;
int maxa = 0;
while (finds < time[time.size() - 1].second)
{
int count = 0;
for (int i = 0; i < time.size(); i++)
{
if (time[i].second < finds || time[i].first > finde)
{
continue;
}
else
{
count++;
}
}
if (maxa < count)
{
maxa = count;
}
if(!flag)
{
finds = time[c].first;
finde = finds + 1000 -1;
flag = true;
}
else
{
finds = time[c].second;
finde = finds + 1000 -1;
c++;
flag = false;
}
}
int answer = maxa;
return answer;
}
반응형
'Algorithm' 카테고리의 다른 글
2018 KAKAO BLIND RECRUITMENT[1차] 다트 게임 (0) | 2020.05.08 |
---|---|
2018 KAKAO BLIND RECRUITMENT[1차] 비밀지도 (0) | 2020.05.08 |
1248. [S/W 문제해결 응용] 3일차 - 공통조상 (0) | 2020.05.07 |
1265. [S/W 문제해결 응용] 9일차 - 달란트2 (0) | 2020.05.06 |
1259. [S/W 문제해결 응용] 7일차 - 금속막대 (0) | 2020.05.05 |