#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<string> lines)
{
int answer = 0;
vector < pair<int, int> > timeVec = {};
int firstCol = 0;
int secondCol = 0;
int firstSpace = 0;
int secondSpace = 0;
int firstCom = 0;
int iHour = 0;
int iMin = 0;
int iSecond = 0;
int iTime = 0;
int iEndTime = 0;
int iProcessSecond = 0;
for (int i = 0; i < lines.size(); ++i)
{
firstCol = lines[i].find(":");
secondCol = lines[i].find(":", firstCol + 1);
firstSpace = lines[i].find(" ");
secondSpace = lines[i].find(" ", firstSpace + 1);
firstCom = lines[i].find(".");
// 시간 분 초로 나눔
iHour = stoi(string(lines[i], firstSpace + 1, firstCol - firstSpace - 1)) * 60 * 60* 1000;
iMin = stoi(string(lines[i], firstCol + 1, secondCol - firstCol - 1)) * 60 * 1000;
iSecond = (int)(stod(string(lines[i], secondCol + 1, secondSpace - secondCol - 1)) * 1000);
iTime = iHour + iMin + iSecond;
// 처리 시간을 double로
iProcessSecond = (int)(stod(string(lines[i], secondSpace + 1, lines[i].size() - secondSpace - 2))* 1000);
iEndTime = iTime - iProcessSecond + 1;
timeVec.push_back({ iTime, iEndTime });
}
for (int i = 0; i < timeVec.size(); ++i)
{
int iFirstCount = 0;
for (int j = 0; j < timeVec.size(); ++j)
{
if (timeVec[i].first <= timeVec[j].first && timeVec[i].first + 1000 > timeVec[j].second)
++iFirstCount;
else if (timeVec[i].first <= timeVec[j].first && timeVec[i].first - 1000 > timeVec[j].second)
++iFirstCount;
}
if (iFirstCount > answer)
answer = iFirstCount;
int iSecondCount = 0;
for (int j = 0; j < timeVec.size(); ++j)
{
if (timeVec[i].second <= timeVec[j].first && timeVec[i].second + 1000 > timeVec[j].second)
++iSecondCount;
else if (timeVec[i].second <= timeVec[j].first && timeVec[i].second - 1000 > timeVec[j].second)
++iSecondCount;
}
if (iSecondCount > answer)
answer = iSecondCount;
}
return answer;
}
하는데 정말 어지러웠다...
처음에는 아예 이해를 잘못해서 초당 map에 저장해서 했었는데 그 초가 아니라 어떤 특정한 1초에 대해서 트래픽을 찾는 거라 아예 갈아엎었다...
두번째로 문제였던 건 1초가 0~999였다는 건데... 계속 0~1000 해 놓고 아 왜 안대지... 왜 안대지... 이러고 있었네...
하면서 배열은 0부터 시작한다는 걸 다시 상기하게 되었다... 정말 처음부터 다시 배운? 그런 기분...
엄청 오래걸렸네
풀고나니 다른 사람이 한 풀이 중에 정말 좋은 게 있어서 혹시라도 못봤다면 추천하는
sscanf(lines[i].c_str(), "%d-%d-%d %d:%d:%d.%d %lfs", &y, &m, &d, &hh, &mm,&ss, &zzz, &elapsed_double);
이런 방법도 있더라~ 라고 생각해보시면 될듯
'오늘의 알고리즘' 카테고리의 다른 글
[C++]2017 카카오코드 본선단체사진 찍기(프로그래머스 2레벨) (0) | 2022.01.27 |
---|---|
[C++][카카오 인턴] 키패드 누르기(프로그래머스 1레벨) (0) | 2022.01.26 |
[C++]2019 KAKAO BLIND RECRUITMENT 오픈채팅방(프로그래머스 2레벨) (0) | 2022.01.24 |
[C++]2021 카카오 채용연계형 인턴십 숫자 문자열과 영단어(프로그래머스 1레벨) (0) | 2022.01.23 |
[C++]2022 KAKAO BLIND RECRUITMENT 신고 결과 받기 (프로그래머스 1레벨) (0) | 2022.01.23 |