hdoj 1702 ACboy needs your help again!
来源:互联网 发布:知乎自媒体平台 编辑:程序博客网 时间:2024/06/07 07:09
ACboy needs your help again!
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 24 Accepted Submission(s) : 16
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.
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题意:fifo:先进先出;-------用队列filo:先进后出;-------用栈根据情况混合栈和队列!代码:#include<stdio.h>#include<queue>#include<stack>#include<algorithm>using namespace std;int main(){ int n; scanf("%d",&n); while(n--) { int m; char a[5]; scanf("%d%s",&m,a); if(a[2]=='F')//先进先出,用队列进出 { queue<int>Q; while(m--) { char b[5]; int t,top=0; scanf("%s",b); if(b[0]=='I')//进队 { scanf("%d",&t); Q.push(t); } else//出队 { if(Q.size()==0 )//判断队是否为空! printf("None\n"); else { printf("%d\n",Q.front() ) ;//出队 Q.pop() ; } } } } else//否则用栈 { stack<int>st; while(m--) { char e[5]; int s; scanf("%s",e); if(e[0]=='I')//进队 { scanf("%d",&s); st.push(s); } else//出队 { if(st.size ()==0 )//判断是否为空 printf("None\n"); else { int y=st.top() ; printf("%d\n",y);//出栈 st.pop() ; } } } } } return 0; }
0 0
- HDOJ 1702 ACboy needs your help again!
- hdoj 1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!
- hdoj 1702 ACboy needs your help again!
- hdoj-1702-ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!
- HDOJ-1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!
- HDOJ-1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again! (stack & queue)
- 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!
- Unix时间戳转换(python)
- 蓝桥杯练习系统(算法训练)-ALGO-2最大最小公倍数
- XCode小道
- 【代码练习】学生成绩排名--涉及IO流和集合
- 二进制值和十六进制字符串相互转换的C++代码
- hdoj 1702 ACboy needs your help again!
- hdu 2082 找单词 母函数
- 关于swt 和一些小技巧
- Chapter 7 String to Integer
- LeetCode 7 反转数字
- jdk的配置与测试
- codeforces round# 302 (div1 C) (状压dp)
- 数据库Sharding的基本思想和切分策略
- 局域网中其他电脑访问我的电脑上的apache服务器