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