์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[๋ฐฑ์ค€(BOJ)] 10828๋ฒˆ: ํ (ํ, C++)

PROGRAMMING/Algorithm

by koharin 2021. 8. 7. 15:50

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ“„ ๋ฌธ์ œํ’€์ด ๊ณผ์ •


C++ STL queue๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ๋ฅผ ๊ตฌํ˜„ํ–ˆ๋‹ค.

๊ธฐํƒ€ ๊ตฌํ˜„ ๋ฐฉ๋ฒ•์€ [๋ฐฑ์ค€(BOJ)] 10828๋ฒˆ: ์Šคํƒ ๊ณผ ๋™์ผํ•˜๋‹ค.

 

 

๐Ÿ’ป ์ฝ”๋“œ


#include <bits/stdc++.h>
using namespace std;

int main(){
    queue<int> q;
    int N;
    scanf("%d", &N);

    for(int i=0; i<N; i++){
        string str; getline(cin >> ws, str);
        switch(str[0]){
            case 'p':
            {
                if(str[1] == 'u'){
                    q.push(stoi(str.substr(str.find(" ")+1)));
                }else{
                    if(q.empty()) printf("-1\n");
                    else{
                        printf("%d\n", q.front());
                        q.pop();
                    }
                }
            }
            break;
            case 's':
            printf("%ld\n", q.size());
            break;
            case 'e':
            printf("%d\n", (q.empty() ? 1 : 0));
            break;
            case 'f':
            printf("%d\n", (q.empty() ? -1 : q.front()));
            break;
            case 'b':
            printf("%d\n", (q.empty() ? -1 : q.back()));
            break;
        }
    }
}

 

 

๐Ÿ–จ ์ œ์ถœ๊ฒฐ๊ณผ


728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ