【hdu 1702】 ACboy needs your help again!
来源:互联网 发布:如何抢注域名赚钱 编辑:程序博客网 时间:2024/06/07 05:53
ACboy needs your help again!
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!
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
44 FIFOIN 1IN 2OUTOUT4 FILOIN 1IN 2OUTOUT5 FIFOIN 1IN 2OUTOUTOUT5 FILOIN 1IN 2OUTIN 3OUT
122112None23
代码:
#include<cstdio>#include<cstring>#include<stack>#include<queue>#include<algorithm>using namespace std;int main(){int m;scanf("%d",&m);while(m--){int n,i,a[1000];char s[5],c[4],s1[5]="FIFO",s2[5]="FILO",c1[3]="IN",c2[4]="OUT";scanf("%d %s",&n,s);if(strcmp(s,s1)==0){queue<int > q;for(i=0;i<n;i++){scanf("%s",c);if(strcmp(c,c1)==0){scanf("%d",&a[i]);q.push(a[i]);}else if(strcmp(c,c2)==0) {if(!q.empty()){int x=q.front();printf("%d\n",x);q.pop();}else{printf("None\n");}} }} else if(strcmp(s,s2)==0){stack<int > q;for(i=0;i<n;i++){scanf("%s",c);if(strcmp(c,c1)==0){scanf("%d",&a[i]);q.push(a[i]);}else if(strcmp(c,c2)==0){if(!q.empty()){ int x=q.top(); printf("%d\n",x); q.pop();}else{printf("None\n");}} }}}}
阅读全文
0 0
- 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!
- 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 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!
- python 3 day3
- Android——App内文件分享功能
- 动态加载css方法实现和深入解析
- js中的this关键字详解
- P1088 火星人
- 【hdu 1702】 ACboy needs your help again!
- springboot+mybatis日志显示SQL的最简单方法
- 数组去重(方法)
- RocketMQ存储篇——IndexFile和IndexService
- 单向链表反转
- hdu6090 Rikka with Graph 2017多校第五场1006 找规律
- ES6代码转为ES5代码的在线转换工具
- 二叉树、B树、B+树、B*树和R树小记
- ViewPager的基础使用介绍