-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaekjoon_10828.cpp
56 lines (46 loc) · 1.11 KB
/
baekjoon_10828.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;
int main(void){
int n;
cin >> n;
vector <int> store;
for(int i = 0; i < n; i++){
string check;
cin >> check;
if (check == "push"){
int temp;
cin >> temp;
store.push_back(temp); // push data
}
else if(check == "pop"){
if (store.size() == 0){
cout << "-1\n";
continue;
}
cout << store[store.size() - 1] << "\n";
store.pop_back();
}
else if(check == "size"){
cout << store.size() << "\n";
}
else if(check == "empty"){
if (store.size() == 0){
cout << "1\n";
continue;
}
else cout << "0\n";
}
else if(check == "top"){
if (store.size() == 0){
cout << "-1\n";
continue;
}
cout << store[store.size() - 1] << "\n";
}
}
return 0;
}