题目:

ACboy needs your help again!

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 73 Accepted Submission(s): 57
 
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
 
 
Source
2007省赛集训队练习赛(1)
 
Recommend
lcy

题目分析:

栈和队列的基本使用,简单题。

事实上出题人的意思可能是让我们自己手写一个栈和队列。可是,作为一个早就知道STL的渣渣来说,是没有耐心再去写stack和queue了。。

。哎哎。。

代码例如以下:

/*
* a.cpp
* 栈和队列的模拟
*
* Created on: 2015年3月19日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue> using namespace std; int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
string type;
cin >> n >> type; if(type == "FIFO"){
queue<int> q;
string cmd;
int num; int i;
for(i = 0 ; i < n ; ++i){
cin >> cmd; if(cmd == "IN"){
cin >> num;
q.push(num);
}else{
if(q.empty() == true){
printf("None\n");
}else{
int ans = q.front();
q.pop();
printf("%d\n",ans);
}
}
} }else{
stack<int> st;
string cmd;
int num; int i;
for(i = 0 ; i < n ; ++i){
cin >> cmd; if(cmd == "IN"){
cin >> num;
st.push(num);
}else{
if(st.empty() == true){
printf("None\n");
}else{
int ans = st.top();
st.pop();
printf("%d\n",ans);
}
}
}
}
} return 0;
}

(hdu step 8.1.1)ACboy needs your help again!(STL中栈和队列的基本使用)的更多相关文章

  1. 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 ...

  2. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

    称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  3. (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)

    题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  4. (hdu step 7.1.3)Lifting the Stone(求凸多边形的重心)

    题目: Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  5. (hdu step 7.1.2)You can Solve a Geometry Problem too(乞讨n条线段,相交两者之间的段数)

    称号: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...

  6. (hdu step 6.3.5)Card Game Cheater(匹配的最大数:a与b打牌,问b赢a多少次)

    称号: Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  7. (hdu step 6.3.7)Cat vs. Dog(当施工方规则:建边当观众和其他观众最喜爱的东西冲突,求最大独立集)

    称号: Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  8. (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)

    称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  9. (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )

    题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

随机推荐

  1. php sortable 动态排序

    php sortable 动态排序未分页版.php 预览图: <?php mysql_connect("localhost","root","r ...

  2. 部署测试环境(ubuntu+mysql+tomcat)

    背景:入职新公司,广州这边没有测试开发环境,需要自己搭建一个:要求ubuntu+mysql+tomcat有具体版本要求:   2015/4/13 下载Ubuntu12.04 http://mirror ...

  3. 猎豹使用AI RoboForm填表

    最近,Chrome同步书签好慢,另外因为工作的原因,chrome还是用来做工作的事情,自己的事情准备换到猎豹,但是一个重要的问题是强大的自动填表工具AI RoboForm没有整合到猎豹的地方: 搜索了 ...

  4. 判断CString字符串中各位是数字,大小写字母,符号,汉字.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#e9e9ff; font-size:16px;}.sysFunc{color:#627cf6; ...

  5. 如何配置仿真器DM8127+SEED-XDS560v2PLUS和连接不上的问题的解决

    1 根据配置焊接JTAG电路转接板.我用的是14pin的. 2 安装仿真器驱动.安装完如下图 我安装的时候没有自动装上,第一次显示问号,后来手动的. 3 设置ccs工程 4 最后调试是这个样子 5 查 ...

  6. OpenGl从零开始之坐标变换(上)

    坐标变换是深入理解三维世界的基础,非常重要.学习这部分首先要清楚几个概念:视点变换.模型变换.投影变换.视口变换. 在现实世界中,所有的物体都具有三维特征,但计算机本身只能处理数字,显示二维的图形,因 ...

  7. asp.net mvc下ckeditor使用

    资源下载:ckeditor 第一步,引入必须文件“~/ckeditor/ckeditor.js” 第二步,替换文本域 <%: Html.TextArea("Content", ...

  8. MySQL Connector_J_5.1.34_2014.10

    5.1版本符合JDBC3.0和JDBC4.0规范 跟MySQL4.1-5.7兼容 5.1.21以后支持JDK7的JDBC4.1规范 在MySQL4.1之前,是不支持utf8的 com.mysql.jd ...

  9. 第二百一十二天 how can I 坚持

    在家待了一天,过个周六日也就这样,时间.感觉好堕落. 下午心情特烦闷.好想结婚.为什么不认输,为什么会这样.这到底是一种什么心态. 哎.不懂自己. 睡觉. fordream.

  10. tomcat的 JNDI 配置

    tomcat的conf/server.xml 配置 尽量用简单版 <Context path="/cas" docBase="D:\YC\zqV7\cas\WebR ...