杭电(hdu)1702 ACboy needs your help again!
来源:互联网 发布:端口能ping吗 编辑:程序博客网 时间:2024/05/17 02:23
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4477 Accepted Submission(s): 2291
Problem Description
ACboy was kidnapped!!
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!
Input
The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
Output
For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.
Sample Input
44 FIFOIN 1IN 2OUTOUT4 FILOIN 1IN 2OUTOUT5 FIFOIN 1IN 2OUTOUTOUT5 FILOIN 1IN 2OUTIN 3OUT
Sample Output
122112None23使用STL类库,stack和queue,注意使用完之后要将栈和队列清空代码如下:#include <iostream>#include <queue>#include <stack>#include <string>using namespace std;int main(){queue<int> q;stack<int> s;int N,n,number;string ss,a;cin>>N;while(N--){cin>>n>>ss;if(ss=="FIFO"){while(n--){cin>>a;if(a=="IN"){cin>>number;q.push(number);}else{if(q.empty()) cout<<"None"<<endl;else{cout<<q.front()<<endl;q.pop();}}}}if(ss=="FILO"){while(n--){cin>>a;if(a=="IN"){cin>>number;s.push(number);}else{if(s.empty()) cout<<"None"<<endl;else{cout<<s.top()<<endl;s.pop();}}} } while(!s.empty()) { s.pop();}while(!q.empty()) { q.pop();}}return 0;}
0 0
- 杭电(hdu)1702 ACboy needs your help again!
- 【HDU 杭电 1702】ACboy needs your help again!
- 杭电ACboy needs your help again!
- 杭电1702 ACboy needs your help again!
- 杭电1702 ACboy needs your help again!
- 杭电1702ACboy needs your help again!
- 【杭电】[1702]ACboy needs your help again!
- 杭电-1702 ACboy needs your help again!(栈&队列)
- HDU 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- HDU-ACboy needs your help again!-1702
- hdu 1702 ACboy needs your help again
- HDU 1702 ACboy needs your help again!
- HDU-1702-ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu---1702ACboy needs your help again!
- HDU - 1702 ACboy needs your help again!
- 上机编程题-迷宫问题
- 文章标题
- Redis服务器剖析
- Android高仿微信图片多选功能
- Android中View属性大全
- 杭电(hdu)1702 ACboy needs your help again!
- Oracle如何&操作进行二进制的比对
- jQuery 效果 - toggle() 方法
- C#遍历查询文本框是否为空,判断文本框是否为数字,一键清空文本框内容
- GridView的一些特殊属性
- vim 配置
- J2EE 总结
- Oracle初探(一)
- Windows10中的IIS10安装php manager和IIS URL Rewrite 2.0组件的方法