https://programmers.co.kr/learn/courses/30/lessons/17678
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<int> tm;
string solution(int n, int t, int m, vector<string> timetable) {
string answer = "";
for(int i=0; i<timetable.size(); i++){
int hour = stoi(timetable[i].substr(0,2)) * 60;
int min = stoi(timetable[i].substr(3,2));
tm.push_back(hour+min);
}
sort(tm.begin(),tm.end());
int curtime = 9*60;
int index = 0;
int ans = 0;
for(int i=0; i<n; i++){
int j=0;
for(; j<m && index < tm.size(); j++){
if(tm[index] <= curtime){
index++;
}
else{
break;
}
}
if(i == n-1){
if(j==m){
ans = tm[index-1]-1;
}
else
ans = curtime;
}
else curtime += t;
}
string tmp = "";
int hour = ans/60;
if(hour <10) tmp +="0"+to_string(hour);
else tmp+=to_string(hour);
tmp +=":";
int min = ans%60;
if(min<10) tmp += "0" + to_string(min);
else tmp+= to_string(min);
answer = tmp;
return answer;
}
'프로그래머스' 카테고리의 다른 글
징검다리 건너기 C++ (0) | 2021.10.06 |
---|---|
도둑질 C++ (0) | 2021.10.06 |
다단계 칫솔 C++ (0) | 2021.10.03 |
불량 사용자 C++ (0) | 2021.10.02 |
자물쇠와 열쇠 C++ (0) | 2021.08.22 |