[2018 카카오 블라인드 채용 1차 코딩 테스트] 셔틀버스
2018 KAKAO BLIND RECRUITMENT :: 2018 카카오 블라인드 채용 1차 코딩 테스트 :: 셔틀버스
출처 : https://programmers.co.kr/learn/courses/30/lessons/17678#
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
string solution(int n, int t, int m, vector<string> timetable) {
string answer = "";
int arr[2000], ans;
int num = timetable.size();
for (int i = 0; i < num; i++) {
arr[i] = ((((timetable[i].at(0) - '0') * 10) + (timetable[i].at(1) - '0')) * 60)
+ (((timetable[i].at(3) - '0') * 10) + (timetable[i].at(4) - '0'));
}
sort(arr, arr + num);
int bus = 540;
if (num < m) ans = bus + ((n - 1)*t);
else {
if (num == m && n == 1) ans = arr[num - 1] <= bus ? arr[num - 1] - 1 : bus;
else {
int wh = 0; int tmp = 0; int z = n;
while (1) {
if (tmp == m) {
tmp = 0; bus += t;
z--;
if (z > 0 && wh == num) {
ans = 540 + ((n - 1)*t);; break;
}
if (z == 0) {
if (wh == 0) wh += 1;
ans = arr[wh - 1] - 1; break;
}
}
if (arr[wh] <= bus && arr[wh]>0) {
tmp++;wh++;continue;
}
else {
if (z == 1) { ans = bus; break; }
tmp++;
}
}
}
}
if ((ans / 60) < 10) answer += "0"; answer += to_string(ans / 60);
ans %= 60; answer += ":";
if (ans < 10) answer += "0"; answer += to_string(ans);
return answer;
}