728x90
https://softeer.ai/practice/6266
ํ๋ ์ํํฐ์ด Lv2. ํ์์ค ์์ฝ C++ ํ์ด
์ฒซ ์ ์ถ์์ Subtask 2๊ฐ๊ฐ ์ค๋ต์ผ๋ก ๋ด๋ค.
์ ์ผ ๊ฐ๋จํ ๋ฐ๋ก ํ์๋ฒ์ธ ๋ธ๋๋ฐ์ค-๊ฒฝ๊ณ๊ฐ ๋ถ์์ผ๋ก ๋ฐ๋ก๋ฅผ ์ฐพ์๋ณด์!
-> ์๋ ์ผ์ด์ค์์, b๋ 17-18์ด ๊ฐ๋ฅํ๋ฐ not available์ด ์ถ๋ ฅ๋จ
2 2
a b
a 9 10
b 9 17
๊ฐ๋ฅํ ์๊ฐ๋ pair๋ฅผ ๊ตฌํ ๋, ๋ฐ๋ณต๋ฌธ์ด ๋๋ ๋ค์ isAble true ์ค์ ์ ์ํด์ค์ ์๊ฒผ๋ ์ค๋ฅ.
์ถ๊ฐํด์คฌ๋๋ ํต๊ณผ!!
#include<iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main(int argc, char** argv)
{
int room; int meeting;
string r; int s; int t;
vector<string> roomName;
vector< pair<string, pair<int,int>> > meetlist;
queue<pair<int,int>> ableTime;
cin >> room >> meeting;
for(int i=0; i<room; ++i) {
cin >> r;
roomName.push_back(r);
}
for(int i=0; i<meeting; ++i){
cin >> r >> s >> t;
meetlist.push_back({r,{s,t}});
}
sort(roomName.begin(), roomName.end());
for(int i=0; i<room; ++i){
bool isAble = false;
string rname = roomName[i];
cout << "Room " << rname <<":\n";
int timelist[10] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
for(int j=0; j<meeting; ++j){ // ๋ฏธํ
์๊ฐ ์ก๊ธฐ
if(rname == meetlist[j].first){
int start = meetlist[j].second.first;
int end = meetlist[j].second.second;
for(int k=start; k<end; ++k) timelist[k-9] = 0;
}
}
int stmp = 0;
for(int k=0; k<10; ++k){
if(stmp>0 && timelist[k]<18){
isAble = true;
}
if(stmp>0 && timelist[k]==0){
ableTime.push({stmp, k+9});
stmp = 0;
}
else if(stmp==0 && timelist[k]>0) stmp = k+9;
}
// cout << stmp<<"@@\n";
if(stmp>0 && stmp<18){
ableTime.push({stmp, 18});
isAble = true;
}
if(!isAble) {// ๊ฐ๋ฅํ ์๊ฐ ์์
cout << "Not available\n";
}
else{ // ๊ฐ๋ฅํ ์๊ฐ์ด ์์
cout << ableTime.size() << " available:\n";
while(!ableTime.empty()){
pair<int,int> time = ableTime.front();
ableTime.pop();
if(time.first<10) cout << "0"<< time.first;
else cout << time.first;
cout <<"-"<< time.second <<"\n";
}
}
if(i<room-1) cout << "-----\n";
}
return 0;
}
ํ๋์ทจ์ ๊ธฐ์ ใ ใ
728x90
'๐ ์๊ณ ๋ฆฌ์ฆ > Softeer' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Javascript(NodeJS)/Softeer] Lv1. A+B (0) | 2024.06.27 |
---|---|
[Javascript(NodeJS)/Softeer] Lv1. ๊ทผ๋ฌด ์๊ฐ (0) | 2024.06.27 |
[C++/Softeer] Lv3. ์์๋๋ก ๋ฐฉ๋ฌธํ๊ธฐ (HSAT 7ํ ์ ๊ธฐ ์ฝ๋ฉ ์ธ์ฆํ๊ฐ ๊ธฐ์ถ) (0) | 2024.06.27 |
[C++/Softeer] Lv1. ์ํํ ํจ๋ (0) | 2024.06.26 |
[C++/Softeer] Lv3. ํจ๊ปํ๋ ํจ๋ (0) | 2024.06.26 |