栈练习2
1 #include<cstdio> 2 #include<iostream> 3 #include<stack> 4 using namespace std; 5 int main() 6 { 7 long long n,k,a,t=1; 8 stack<int>ss; 9 cin>>n; 10 while(n--) 11 { 12 cin>>k; 13 if(k==1) 14 { 15 cin>>a; 16 ss.push(a); 17 continue; 18 } 19 if(k==2&&ss.empty()) 20 { 21 t=0;break;//空的时候还出栈就不可以了... 22 } 23 ss.pop(); 24 } 25 if(ss.empty()||t==0) cout<<"impossible!"<<endl; 26 else cout<<ss.top(); 27 return 0; 28 }