Baekjoon #18258

Baekjoon #18258

3개의 풀이 · C++, Java, Python

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include<bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T; cin >> T;
    queue<int> Q;
    while(T--) {
        string cmd; cin >> cmd;
        if(cmd == "push") {
            int X; cin >> X;
            Q.push(X);
        }
        else if(cmd == "pop") {
            if(Q.empty()) cout << -1 << '\n';
            else {
                cout << Q.front() << '\n';
                Q.pop();
            }
        }
        else if(cmd == "size") {
            cout << (int)Q.size() << '\n';
        }
        else if(cmd == "empty") {
            cout << Q.empty() << '\n';
        }
        else if(cmd == "front") {
            if(Q.empty()) cout << -1 << '\n';
            else cout << Q.front() << '\n';
        }
        else if(cmd == "back") {
            if(Q.empty()) cout << -1 << '\n';
            else cout << Q.back() << '\n';
        }
    }

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.