Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- main()
- {
- stack <int> S;
- while(1)
- {
- string s;
- cin>>s;
- if(s == "end") break;
- if(s == "pop")
- {
- // if(S.empty() == 0) cout<<S.top();
- // cout<<endl;
- if(!S.empty())S.pop();
- }
- if(s == "init")
- {
- for(int i = S.size()-1; i >= 0; i--)
- {
- S.pop();
- }
- }
- if(s == "empty")
- {
- if(!S.empty()) cout<<"0";
- else cout<<"1";
- cout<<endl;
- }
- if(s == "push")
- {
- int x;
- cin>>x;
- S.push(x);
- }
- if(s == "top")
- {
- if(!S.empty()) cout<<S.top();
- else cout<<"-1";
- cout<<endl;
- }
- if(s == "size") cout<<S.size()<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement