#include <iostream>
#include <string>
#include <stack>
using namespace std;
stack<int> s;
string res;
void Push(int n) { s.push(n); }
void Pop()
{
if (s.empty())
res += to_string(-1) + '\n';
else
{
res += to_string(s.top()) + '\n';
s.pop();
}
}
void Size() { res += to_string(s.size()) + '\n'; }
void Empty() { res += to_string(s.empty()) + '\n'; }
void Top() { res += to_string(s.empty() ? -1 : s.top()) + '\n'; }
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
for (size_t i = 0; i < n; i++)
{
int opt; cin >> opt;
switch (opt)
{
case 1:
int tmp; cin >> tmp;
Push(tmp);
break;
case 2: Pop(); break;
case 3: Size(); break;
case 4: Empty(); break;
case 5: Top(); break;
}
}
res.pop_back();
cout << res;
return 0;
}
'코딩테스트 > 백준' 카테고리의 다른 글
[실4] 1755 - 숫자놀이 (0) | 2023.08.30 |
---|---|
[실5] 14916 - 거스름돈 (0) | 2023.08.30 |
[실5] 2563 - 색종이 (0) | 2023.08.28 |
[실4] 10845 - 큐 (0) | 2023.08.28 |
[실4] 10816 - 숫자 카드 2 (0) | 2023.08.28 |