栈练习1

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<stack>
 4 using namespace std;
 5 int n,i,k,u;
 6 int main()
 7 {
 8     stack<int>sta;
 9     scanf("%d",&n);
10     for(i=1;i<=n;i++)
11     {
12         scanf("%d",&k);
13         if(k==1)
14         {
15             scanf("%d",&u);
16             sta.push(u);
17         }
18         if(k==2)
19         {
20             sta.pop();
21         }
22     }
23     if(sta.empty())  printf("impossible!");
24     else  printf("%d",sta.top());
25     return 0;
26  } 

 

posted on 2016-03-16 21:01  babyyang  阅读(121)  评论(0编辑  收藏  举报