HDU1702:ACboy needs your help again!
来源:互联网 发布:网络在线对外汉语教师 编辑:程序博客网 时间:2024/05/17 04:53
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
//
赤裸裸的栈和队列的应用
#include <iostream>#include <cstdio>#include <string.h>#include <queue>#include <stack>using namespace std;void que_ex(int n){ queue<int> Q; char s[10]; int a; while(n--) { scanf("%s",s); if(!strcmp(s,"IN")) { scanf("%d",&a); Q.push(a); } else if(!strcmp(s,"OUT")) { if(Q.empty()) printf("None\n"); else { printf("%d\n",Q.front()); Q.pop(); } } }}void sta_ex(int n){ stack<int> S; char s[10]; int a; while(n--) { scanf("%s",s); if(!strcmp(s,"IN")) { scanf("%d",&a); S.push(a); } else if(!strcmp(s,"OUT")) { if(S.empty()) printf("None\n"); else { printf("%d\n",S.top()); S.pop(); } } }}int main(){ int n; while(~scanf("%d",&n)) { while(n--) { int m; char str[100]; scanf("%d%s",&m,str); if(!strcmp(str,"FIFO")) que_ex(m); else if(!strcmp(str,"FILO")) sta_ex(m); else printf("error\n"); } } return 0;}
- ACboy needs your help again! hdu1702
- hdu1702(ACboy needs your help again!)
- HDU1702:ACboy needs your help again!
- ACboy needs your help again!--hdu1702
- HDU1702 ACboy needs your help again!
- HDU1702 ACboy needs your help again! 队列&&栈的应用
- HDU1702 acm 数据结构 ACboy needs your help again!
- hdu1702 ACboy needs your help again!(栈和队列
- HDU1702--ACboy needs your help again!(栈和队列)
- ACboy needs your help again!
- ACboy needs your help again!
- Acboy needs your help again!
- ACboy needs your help again!
- ACboy needs your help again!
- ACboy needs your help again!
- hdu1702(ACboy needs your help again!) 在杭电又遇坑了
- HDU1702:ACboy needs your help again!(栈和队列的应用)
- HDU 1702 ACboy needs your help again!
- 【设计模式】6. 命令模式
- HDU 4515 小Q系列故事——世界上最遥远的距离
- 学vc,加油站(一)区域渐变
- Lab3 ARM指令
- 用友NC二次开发问题汇总【转】
- HDU1702:ACboy needs your help again!
- setContentView() 、LayoutInflater的区别
- spring四种依赖注入方式
- C#调用Windows图片和传真查看器打开图片
- H264与RTP
- Struts2深入学习:OGNL表达式原理
- hdu1568
- 【0】答辩后感想
- 我们在囧途之技术管理者篇