링크 : https://www.acmicpc.net/problem/10828
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
int n = 0;
cin >> n;
vector<int> stack;
for(int i = 0; i < n; i++){
string s;
cin >> s;
if(s == "push"){
int num = 0;
cin >> num;
stack.push_back(num);
}
else if(s == "pop"){
if(stack.empty()) cout << "-1" << endl;
else{
cout << stack.back() << endl;
stack.pop_back();
}
}
else if(s == "size"){
cout << stack.size() << endl;
}
else if(s == "empty"){
if(stack.empty()) cout << "1" << endl;
else cout << "0" << endl;
}
else if(s == "top"){
if(stack.empty()) cout << "-1" << endl;
else cout << stack.back() << endl;
}
}
return 0;
}