题目:

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. Jmeter介绍

    一.添加线程组 一个性能测试请求负载是基于一个线程组完成的.一个测试计划必须有一个线程组.测试计划添加线程组非常简单.在测试计划右键弹出下拉菜单(添加-->Threads(Users)---&g ...

  2. python中的深拷贝与浅拷贝

    深拷贝和浅拷贝 浅拷贝的时候,修改原来的对象,浅拷贝的对象不会发生改变. 1.对象的赋值 对象的赋值实际上是对象之间的引用:当创建一个对象,然后将这个对象赋值给另外一个变量的时候,python并没有拷 ...

  3. spark connect to Cassandra problem

    Cassandra rowkey is Blob type, cannot select by spark. How?

  4. 输出(test)

    本题要求从输入的N个整数中查找给定的X.如果找到,输出X的位置(从0开始数):如果没有找到,输出“Not Found”. 输入格式: 输入在第1行中给出2个正整数N(<=20)和X,第2行给出N ...

  5. ACM2050前传

    n在一个平面上有一个圆和n条直线,这些直线中每一条在圆内 同其他直线相交,假设没有3条直线相交于一点,试问这些直线 将圆分成多少区域.   使用递归 F(1)=2; F(n) = F(n-1)+n; ...

  6. oracle 体系结构解析

    三.oracle 体系结构 1.oracle内存由SGA+PGA所构成 2.oracle数据库体系结构数据库的体系结构是指数据库的组成.工作过程与原理,以及数据在数据库中的组织与管理机制. oracl ...

  7. Ios下解决libzbar.a不支持armv7s的方法

    解决 libzbar.a' for architecture armv7 的问题 下载最新的zbar源码 http://sourceforge.net/p/zbar/code/ci/default/t ...

  8. pip install 下载慢的问题

    建个文件 ~/.pip/pip.conf, 内容如下 [global] timeout = 6000 index-url = https://pypi.doubanio.com/simple [ins ...

  9. (转载)ETL利器Kettle实战应用解析系列一【Kettle使用介绍】

    http://www.cnblogs.com/limengqiang/archive/2013/01/16/kettleapply1.html ETL利器Kettle实战应用解析系列一[Kettle使 ...

  10. HDU 5534 Partial Tree (完全背包变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意: 给你度为1 ~ n - 1节点的权值,让你构造一棵树,使其权值和最大. 思路: 一棵树上 ...