//

//  10828_스택.cpp

//  AlgorithmCpp

//

//  Created by 정경인 on 2018. 12. 3..

//  Copyright © 2018년 kyoungin. All rights reserved.



#include <stdio.h>

#include <string.h>

#include <iostream>

#include <stack>

#define IOFAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std;


int main(){

    IOFAST();

    stack<int> st;

    int i,n;

    string value ;

    cin >> n;

    for(i = 0; i< n ; i++){

        int temp;

        cin >> value;

        if(value == "push"){

            cin >> temp;

            st.push(temp);

        }

        else if(value == "pop"){

            if(!st.empty()){

                temp = st.top();

                st.pop();

                cout <<temp << '\n';

            }else{

                cout << "-1\n";

                

            }

        }

        else if(value == "size"){

            temp = (int)st.size();

            cout << temp << '\n';

        }

        else if(value == "empty"){

            if(!st.empty()){

                cout << 0 << '\n';

            }else{

                cout << 1 << '\n';

            }

        }

        else if(value == "top"){

            if(!st.empty()){

                temp = st.top();

                cout << temp << '\n';

            }else{

                cout << -1 << '\n';

            }

        }

        else {

            cout << "잘못된 입력 \n";

        }

        

    }

}


'Algorithm > 백준 BOJ' 카테고리의 다른 글

[2606] 바이러스  (0) 2018.06.03
[2178] 미로 탐색  (0) 2018.06.02
[10809] 알파벳 찾기  (0) 2018.05.29
[1929] 소수 구하기  (0) 2018.05.28
[2577] 숫자의 개수  (0) 2018.05.24

+ Recent posts