HDOJ 1702 ACboy needs your help again! (STL 栈 队列)
来源:互联网 发布:淘宝饰品店装修图 编辑:程序博客网 时间:2024/06/06 23:52
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2452 Accepted Submission(s): 1254Problem 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!
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
122112None23STL的应用贴一下队列和栈的基本用法代码:#include<iostream>#include<queue>#include<stack>#include<cstdio>#include<cstring>#include<ctype.h>using namespace std;int n;void FIFO (){ queue<int> ss; char ch[10]; int p,i; for (i=0; i<n; i++) { scanf("%s", ch); if (strcmp(ch,"IN")==0) { cin>>p; ss.push(p); } else { if (!ss.empty()) { cout<<ss.front()<<endl; ss.pop(); } else cout<<"None"<<endl; } } return;}void FILO (){ stack<int> ss; char ch[10]; int p,i; for (i=0; i<n; i++) { scanf("%s", ch); if (strcmp(ch,"IN")==0) { cin>>p; ss.push(p); } else { if (!ss.empty()) { cout<<ss.top()<<endl; ss.pop(); } else cout<<"None"<<endl; } } return;}int main (){ int t,i; string st; char ch[10]; cin>>t; while (t--) { cin>>n; cin>>st; if (st=="FIFO") FIFO(); else if (st=="FILO") FILO(); } return 0;}
- HDOJ 1702 ACboy needs your help again! (STL 栈 队列)
- HDU - 1702 - ACboy needs your help again!(栈&&队列)
- HDU 1702 ACboy needs your help again!(栈+队列)
- 【HDU】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!
- HDOJ 1702 ACboy needs your help again!
- HDOJ-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!(模拟 队列 栈)
- jquery.validate.js表单验证
- pickle模块
- 【2013-06-10】首章
- Document多种方式解析xml文件
- Android玄铁剑之TextView之写点儿嘛都行
- HDOJ 1702 ACboy needs your help again! (STL 栈 队列)
- ./configure 权限不够
- Servlet读出一条记录
- HDOJ 1509 Windows Message Queue (优先队列)
- swt实现外部文件拖曳到界面
- 什么是网络虚拟化?
- 深入理解Oracle索引(22):索引和NULL 协同合作互惠共赢
- 欧拉函数
- 01背包问题(回溯算法实现)
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
失眠快速睡十招
失眠怎么办才好
总失眠是怎么回事
失眠是什么病的前兆
抑郁失眠怎么办
失眠图片搞笑
产妇失眠怎么办
失眠图片可爱配图
一直失眠该怎么办
失眠的好方法
我为什么失眠
失眠该怎么办啊
老失眠是什么原因
失眠是何原因
半夜失眠是怎么回事
我失眠怎么办
总失眠是什么原因
经常失眠会怎样
解决失眠的好方法
晚上失眠咋回事
严重失眠了怎么办
老是失眠怎么办
人为什么失眠呢
失眠很严重怎么办
失眠是为什么
如果失眠了怎么办
天天失眠是怎么回事
晚上老是失眠
失眠有什么解决办法
经常失眠应该怎么办
总是失眠什么原因
晚上失眠怎么回事
失眠怎么样的
经常失眠什么原因
严重失眠怎么办啊
我失眠了怎么办
总失眠的原因
突然失眠原因
失眠是如何导致的
失眠咋办才好
失眠吃什么好呢