题目:

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

    1.Stream (流) Stream有四种流类型 1.Readable - 可读操作 2.Writable - 可写操作 3.Duplex - 可读可写操作 4.Transform - 操作被写入数 ...

  2. SCAU 13校赛 17115 ooxx numbers

    17115 ooxx numbers 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description a number A called oo numbe ...

  3. dom 留言加强

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 转】MyEclipse使用总结——MyEclipse去除网上复制下来的来代码带有的行号

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/3544208.html 感谢! 一.正则表达式去除代码行号 作为开发人员,我们经常从网上复制一些代码,有些时候复制 ...

  5. 简单版问卷调查系统(Asp.Net+SqlServer2008)

    1.系统主要涉及以下几个表  问卷项目表(Q_Naire) 问卷题目表(Q_Problem) 题目类型表(Q_ProblmeType) 题目选项表(Q_Options) 调查结果表(Q_Answer) ...

  6. HDU 1002 分类: ACM 2015-06-18 23:03 9人阅读 评论(0) 收藏

    昨天做的那题其实和大整数相加类似.记得当初我大一寒假就卡在这1002题上,结果之后就再也没写题... 到今天终于把大整数相加写了一遍. 不过写的很繁琐,抽时间改进一下写简洁一点. #include&l ...

  7. ubuntu 64位系统下加速Android模拟器

    安装KVM: sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils 在Postfix Configurati ...

  8. labview图形和图表的类型

    http://zone.ni.com/reference/zhs-XX/help/371361L-0118/lvconcepts/types_of_graphs_and_charts/ LabVIEW ...

  9. 用python实现远程复制 (scp + expect )

    scp 功能很强大,但需要人工输入 password, 当然可以通过把 公钥保存在远程主机的 ~/.ssh 目录中,而后就不用输入password,但这需要配置. 用 sshpass 可能在命令输入 ...

  10. MSSQL手札四 MSSQL的函数

    和oracle一样,sql也可以自己定义函数 一个返回值,引用DEMO如下: 编写一个函数,该函数,可以通过输入借书时间来判断是否到期,当借阅时间大于30天,返回已经过期:否则返回还未到期. CREA ...