hdu1702_ACboy needs your help again!

 1 #include<iostream>
 2 #include<stack>
 3 #include<queue>
 4 #include<string> 
 5 using namespace std;
 6 int main(){
 7     int t,n,temp;
 8     cin>>t;
 9     while(t--){
10         queue<int> Q;
11         stack<int> S;
12         string str1,str2;
13         cin>>n>>str1;
14         for(int i=0;i<n;i++){
15             if(str1=="FIFO"){
16             cin>>str2;
17             if(str2=="IN"){
18                 cin>>temp;
19                 Q.push(temp);
20             }
21             if(str2=="OUT"){
22                 if(Q.empty())cout<<"None"<<endl;
23                 else{
24                     cout<<Q.front()<<endl;//返回队列首元素
25                     Q.pop();//删除队列首元素
26                 }
27             }
28         }
29         if(str1=="FILO"){
30             cin>>str2;
31             if(str2=="IN"){
32                 cin>>temp;
33                 S.push(temp);
34             }
35             if(str2=="OUT"){
36                 if(S.empty())cout<<"None"<<endl;
37                 else{
38                     cout<<S.top()<<endl;//返回栈顶元素
39                     S.pop();//删除栈顶元素
40                 }
41             }
42         }
43         }
44         
45     }
46     return 0;
47 } 

注:模拟栈和队列

猜你喜欢

转载自www.cnblogs.com/bxynlbyx/p/12811638.html