๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Softeer

[C++/Softeer] Lv2. ํšŒ์˜์‹ค ์˜ˆ์•ฝ

https://softeer.ai/practice/6266

 

Softeer - ํ˜„๋Œ€์ž๋™์ฐจ๊ทธ๋ฃน SW์ธ์žฌํ™•๋ณดํ”Œ๋žซํผ

 

softeer.ai

 

ํ˜„๋Œ€ ์†Œํ”„ํ‹ฐ์–ด 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;
}

 

 

ํ˜„๋Œ€์ทจ์—…๊ธฐ์› ใ…‹ใ…‹