https://school.programmers.co.kr/learn/courses/30/lessons/155651
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
int solution(vector<vector<string>> book_time) {
vector<int> rooms;
std::sort(book_time.begin(), book_time.end());
std::for_each(book_time.begin(), book_time.end(), [&](const auto& v) {
stringstream ss1(v.front());
stringstream ss2(v.back());
string buffer;
vector<int> temp;
while (getline(ss1, buffer, ':')) temp.emplace_back(stoi(buffer));
int s_time = temp[0] * 60 + temp[1];
temp.clear();
while (getline(ss2, buffer, ':')) temp.emplace_back(stoi(buffer));
int e_time = temp[0] * 60 + temp[1];
for (size_t i = 0; i < rooms.size(); ++i)
{
if (rooms[i] <= s_time)
{
rooms[i] = e_time + 10;
return;
}
}
rooms.emplace_back(e_time + 10);
});
return rooms.size();
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (2021 Dev-Matching: 웹 백엔드 개발자(상반기)) Lv 2. 행렬 테두리 회전하기 (0) | 2023.11.14 |
---|---|
[Programmers] (그리디 or 완전탐색) Lv 2. 마법의 엘리베이터 (0) | 2023.11.10 |
[Programmers] (2020 카카오 인턴십) Lv 2. 수식 최대화 (0) | 2023.10.10 |
[Programmers] (완전탐색) Lv 2. 전력망을 둘로 나누기 (0) | 2023.08.08 |
[Programmers] (2020 KAKAO BLIND RECRUITMENT) Lv 2. 괄호 변환 (0) | 2023.08.07 |
댓글