#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
int N, temp;
cin >> N;
string action;
vector<int> arr;
for(int i = 0; i < N; i++) {
cin >> action;
if(action == "push") {
cin >> temp;
arr.push_back(temp);
} else if(action == "top") {
arr.empty() ? cout << -1 << endl : cout << arr.back() << endl;
} else if(action == "size") {
cout << arr.size() << endl;
} else if(action == "empty") {
cout << arr.empty() << endl;
} else {
if(arr.empty()) cout << -1 << endl;
else {
cout << arr.back() << endl;
arr.pop_back();
}
}
}
}
dd
문제: https://www.acmicpc.net/problem/10828
'Problem Solving > 백준' 카테고리의 다른 글
[백준/C++] 1427번 소트인사이드 (0) | 2022.01.26 |
---|---|
[백준/C++] 11650번 좌표 정렬하기 (0) | 2022.01.24 |
[백준/C++] 8958번 OX퀴즈 (0) | 2022.01.24 |
[백준/C++] 5622번 다이얼 (0) | 2022.01.24 |
[백준/C++] 5598번 카이사르 암호 (0) | 2022.01.24 |