728x90
https://softeer.ai/practice/6266
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
string formatString(int time)
{
string s = to_string(time);
return s.size() < 2 ? "0" + s : s;
}
int main(int argc, char** argv)
{
int n, m;
cin >> n >> m;
string in;
int start, end;
vector<string> roomName;
map<string, vector<int>> room;
for (int i = 0; i < n; i++)
{
cin >> in;
roomName.push_back(in);
room[in] = vector<int>(10);
}
for (int i = 0; i < m; i++)
{
cin >> in >> start >> end;
for (int i = start - 9; i < end - 9; i++)
{
room[in][i] = 1;
}
if (end == 18)
room[in][9] = 1;
}
//예약장소 sort
sort(roomName.begin(), roomName.end());
int count = 1;
for (const auto& roomName : roomName)
{
cout << "Room " + roomName + ":\n";
auto schedule = room[roomName];
vector<string> availableTimes;
int start = -1;
int end = -1;
for (int i = 0; i < schedule.size(); i++)
{
//예약가능한 시작시간을 발견
if (schedule[i] == 0 && start == -1)
{
start = i + 9;
}
//예약된 시간을 발견
else if (schedule[i] == 1 && start != -1)
{
end = i + 9;
string s = formatString(start);
string e = formatString(end);
availableTimes.push_back(s + "-" + e);
start = -1;
end = -1;
}
}
//예약가능 시작시간만 발견 예약된 시간을 발견 못함 그럼 18시까지 가능
if (start != -1)
{
string s = formatString(start);
string e = "18";
availableTimes.push_back(s + "-" + e);
}
//출력
{
if (availableTimes.empty())
cout << "Not available" << endl;
else
{
cout << availableTimes.size() << " available:\n";
for (const auto& time : availableTimes)
{
cout << time << endl;
}
}
if (count != room.size())
cout << "-----" << endl;
}
count++;
}
return 0;
}
728x90
'코딩공부 > Softeer' 카테고리의 다른 글
[Softeer/C++] 나무 섭지 (0) | 2024.11.06 |
---|---|
[Softeer/C++] [한양대 HCPC 2023] Hanyang Popularity Exceeding Competition (0) | 2024.11.05 |
[Softeer/C++] 나무 공격 (0) | 2024.11.04 |
[Softeer/C++] [21년 재직자 대회 예선] 비밀 메뉴 (0) | 2024.03.11 |
[Softeer/C++] 장애물인식 프로그램 (0) | 2024.03.09 |