File tree Expand file tree Collapse file tree 2 files changed +53
-13
lines changed
Expand file tree Collapse file tree 2 files changed +53
-13
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < stack>
3+
4+ using namespace std ;
5+
6+ stack<int > s;
7+ int n;
8+ int main () {
9+ ios::sync_with_stdio (false );
10+ cin.tie (NULL ); cout.tie (NULL );
11+
12+ cin >> n;
13+ for (int i = 0 ; i < n; i++) {
14+ string cmd;
15+ int x;
16+ cin >> cmd;
17+
18+ if (cmd == " push" ) {
19+ cin >> x;
20+ s.push (x);
21+ }
22+ else if (cmd == " pop" ) {
23+
24+ if (s.empty ()) {
25+ cout << -1 << endl;
26+ }
27+
28+ else {
29+ cout << s.top () << endl;
30+ s.pop ();
31+ }
32+ }
33+ else if (cmd == " size" ) {
34+ cout << s.size () << endl;
35+ }
36+ else if (cmd == " empty" ) {
37+ if (s.empty ()) {
38+ cout << 1 << endl;
39+ }else {
40+ cout << 0 << endl;
41+ }
42+ }
43+ else if (cmd == " top" ) {
44+ if (s.empty ()) {
45+ cout << -1 << endl;
46+ }
47+ else {
48+ cout << s.top () << endl;
49+ }
50+ }
51+ }
52+ return 0 ;
53+ }
You can’t perform that action at this time.
0 commit comments