입력
n
n ≦ 10t
t ≦ 60m
m ≦ 45timetable
timetable ≦ 45출력
단순 구현
셔틀 운행 횟수를 순회
count 변수를 통해 현재 버스에 태운 인원 기록timetable에서 태운 마지막 idx 기록count++i==n-1)
count가 수용인원 m과 같으면
문자열 ↔ 정수
// "09:00" -> 540
// substr(a, b) -> 인덱스 a에서 시작해 b개의 부분 문자열
string h = time.substr(0, 2); // "09"
string m = time.substr(3, 2); // "00"
// stoi -> 문자열을 정수로 변환
i_table.push_back(stoi(h) * 60 + stoi(m));
// 정수를 문자열로
// to_string -> 정수를 문자열로
string ans = (hh < 10 ? "0" : "") + to_string(hh) + ":";
ans += (mn < 10 ? "0" : "") + to_string(mn);
구현
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(int n, int t, int m, vector<string> timetable) {
sort(timetable.begin(), timetable.end());
vector<int> i_table;
for (auto time: timetable) {
string h = time.substr(0, 2);
string m = time.substr(3, 2);
i_table.push_back(stoi(h) * 60 + stoi(m));
}
int current = 9 * 60;
int idx = 0;
int last;
for (int i=0; i<n; i++) {
int count = 0;
for (int j=idx; j<i_table.size(); j++) {
if (i_table[j] <= current) {
idx++;
count++;
if (count==m) break;
}
}
if (i==n-1) {
if (count == m) {
last = i_table[idx-1] -1;
} else {
last = current;
}
}
current += t;
}
int hh = last / 60;
int mn = last % 60;
string ans = (hh < 10 ? "0" : "") + to_string(hh) + ":";
ans += (mn < 10 ? "0" : "") + to_string(mn);
return ans;
}