백준
[10828] 스택
Jcoder
2018. 7. 21. 13:59
#include <iostream>#include <stack>#include <string>using namespace std;int main(){stack <int> st;string str;int testcase;cin >> testcase;for (int i = 0; i < testcase; i++){cin >> str;if (str == "push"){int num;cin >> num;st.push(num);}else if (str == "pop"){if (!st.empty()){cout << st.top() << endl;st.pop();}elsecout << "-1" << endl;}else if (str == "size"){cout << st.size() << endl;}else if (str == "empty"){if (st.empty())cout << "1" << endl;elsecout << "0" << endl;}else if (str == "top"){if (!st.empty())cout << st.top() << endl;elsecout << "-1" << endl;}}return 0;}