-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828_Stack.cpp
More file actions
55 lines (46 loc) · 848 Bytes
/
Copy path10828_Stack.cpp
File metadata and controls
55 lines (46 loc) · 848 Bytes
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
// Baekjoon 10828
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N;
string input;
vector<int>vec;
void push(int n) {
vec.push_back(n);
}
void pop() {
if (vec.size() == 0) cout << "-1\n";
else {
cout << vec[vec.size() - 1] << "\n";
vec.pop_back();
}
}
void size() {
cout << vec.size() << endl;
}
void empty() {
if (vec.size() == 0) cout << "1\n";
else cout << "0\n";
}
void top() {
if (vec.size() == 0) cout << "-1\n";
else cout << vec[vec.size() - 1] << "\n";
}
int main() {
cin.tie();
ios::sync_with_stdio(false);
cin >> N;
for (int i{ 0 }; i < N; i++) {
cin >> input;
if (input == "push") {
int num;
cin >> num;
push(num);
}
else if (input == "pop") pop();
else if (input == "size") size();
else if (input == "empty") empty();
else if (input == "top") top();
}
}