首页 > 其他 > 详细

hdu1702_ACboy needs your help again!

时间:2020-05-01 00:00:58      阅读:53      评论:0      收藏:0      [点我收藏+]
 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 } 

注:模拟栈和队列

hdu1702_ACboy needs your help again!

原文:https://www.cnblogs.com/bxynlbyx/p/12811638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!