#include <iostream> #include <stack> using namespace std; int main(){ int a; stack<int> s; while(cin>>a){ if(a==1){ int b; cin>>b; s.push(b); } if(a==2) cout<<"The top is "<<s.top()<<endl; if(a==3) s.pop(); } return 0; }
时间: 2024-10-14 13:39:53
#include <iostream> #include <stack> using namespace std; int main(){ int a; stack<int> s; while(cin>>a){ if(a==1){ int b; cin>>b; s.push(b); } if(a==2) cout<<"The top is "<<s.top()<<endl; if(a==3) s.pop(); } return 0; }