ACboy needs your help again!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16823    Accepted Submission(s): 8254

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!
 
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
4
4 FIFO
IN 1
IN 2
OUT
OUT
4 FILO
IN 1
IN 2
OUT
OUT
5 FIFO
IN 1
IN 2
OUT
OUT
OUT
5 FILO
IN 1
IN 2
OUT
IN 3
OUT
 
Sample Output
1
2
2
1
1
2
None
2
3
 
这个题的思路其实也很简单,就是模拟栈和队列,来实现对应的操作,主要是为了熟悉queue的使用
#include <iostream>
#include <queue>
#include <stack>
#include <string> using namespace std; int main()
{
int t,n,temp;
cin>>t;
while(t--){
string str,str1;
queue<int>Q;
stack<int>S;
cin>>n>>str;
for(int i = ;i < n; i++){
if(str=="FIFO"){
cin>>str1;
if(str1=="IN"){
cin>>temp;
Q.push(temp);
}
if(str1=="OUT"){
if(Q.empty())
cout<<"None"<<endl;
else{
cout<<Q.front()<<endl;
Q.pop();
}
}
}
else{
cin>>str1;
if(str1=="IN"){
cin>>temp;
S.push(temp);
}
if(str1=="OUT"){
if(S.empty())
cout<<"None"<<endl;
else{
cout<<S.top()<<endl;
S.pop();
}
}
}
}
}
return ;
}

queue的使用-Hdu 1702的更多相关文章

  1. hdu 1702 ACboy needs your help again!

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...

  2. HDU - 1702 ACboy needs your help again!(栈和队列)

    Description ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image ...

  3. HDU 1702 http://acm.hdu.edu.cn/showproblem.php?pid=1702

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> #define ...

  4. HDU 1702 队列与栈的简单运用http://acm.hdu.edu.cn/showproblem.php?pid=1702

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> #define ...

  5. hdu 1702 栈和队列的简单应用

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> using n ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. 第一周训练 | STL和基本数据结构

    A - 圆桌问题: HDU - 4841 #include<iostream> #include<vector> #include<stdio.h> #includ ...

  8. hdu 栈题1022&1702

    http://acm.hdu.edu.cn/showproblem.php?pid=1022 http://blog.csdn.net/swm8023/article/details/6902426此 ...

  9. hdu 1387(Team Queue) STL

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. 【音乐欣赏】《I Do What I Want》 - Missio

    曲名:I Do What I Want 作者:Missio [00:15.84]I wish I could party like I used to when I was young [00:21. ...

  2. Jquery 如何设置多个attr()属性

    Jquery 如何设置多个attr()属性?     文章来源:刘俊涛的博客 欢迎关注公众号.留言.评论,一起学习. _________________________________________ ...

  3. 记录 shell学习过程(9)正则表达式 转自树明聊运维

    正则表达式 正则表达式介绍 特殊字符 POSIX特殊字符 一.正则表达式介绍 正则表达式是一种文本模式匹配,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为"元字符") ...

  4. [CF1220C] Substring Game in the Lesson - 博弈论

    [CF1220C] Description 给定一个字符串 \(S\) , 同时维护一个区间 \([l,r]\) .轮流操作,每次可以扩展到一个新区间使得原区间是新区间的真子区间,并且字典序更小,不能 ...

  5. [WC2006] 水管局长 - Link Cut Tree

    离线后逆序处理所有操作,那么就变成了加边询问,根据MST的性质,显然维护MST询问链上max即可 #include <bits/stdc++.h> using namespace std; ...

  6. Linux异常 时间戳 2018-10-08 11:17:22 是未来的 5288025.776562967 秒之后

    原因:系统时间不对,有可能落后当前实际时间

  7. [POI2007] OSI-Axes of Symmetry

    Description Luogu3454 BZOJ1100 Solution 把边和角顺次放入一个数组里,如果一个点为中心的回文串的半径大于\(n\),那就一定是一个对称轴.跑一遍manacher就 ...

  8. javascript 循环读取数组中的值

    //数组 var a = ["#F85C6F", "#78B0F0", "#DB83ED", "#8EC656", &q ...

  9. java fastjson:Map与json以及JSONObject ,JSONObject与String互转

    import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson ...

  10. c++指针实例

    #include <iostream> using namespace std; int main () { ; // 实际变量的声明 int* ip; // 指针变量的声明 ip = & ...