(hdu step 8.1.1)ACboy needs your help again!(STL中栈和队列的基本使用)
题目:
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 |
Sample Output
1 |
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中栈和队列的基本使用)的更多相关文章
- 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 ...
- (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)
题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- (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 ...
- (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/ ...
- (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 ...
- (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 ...
- (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 ...
- (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数<=3,输出剩下的人 )
题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
随机推荐
- AFNetWorking 使用记录
1.从一个URL GET数据 方法1: NSURL * url = [NSURL URLWithString:@"http://www.weather.com.cn/data/sk/101 ...
- (转载)OC学习篇之---协议的概念和用法
在前一篇文章中我们介绍了OC中类的延展,这一篇文章我们在来看一下OC中协议的概念以及用法,协议也是OC中的一个重点,Foundation框架以及我们后面在写代码都会用到. OC中的协议就是相当于Jav ...
- 【转】SQL Server 数据库内部版本号
-----------数据库还原或版本升级出现版本错误时可参考. Internal SQL Server Database Version Numbers A database created by ...
- [WebService]之TCPMon的使用
TCPMon是apache下的一个项目,下载地址:http://ws.apache.org/commons/tcpmon/download.cgi (1)功能: TCPMon可以拦截客户与服务之间的H ...
- 【CLR】奇妙的String
- 一.背景 1. 以下代码的HashCode是否相同,它们是否是同个对象: var A = "ab" + "c"; var B = "abc&quo ...
- Hadoop学习笔记3---安装并运行Hadoop
本文环境是在Ubuntu10.04环境下运行的. 在Linux上安装Hadoop之前,首先安装两个程序: 1.JDK1.6(或更高版本).Hadoop是用Java编写的程序,Hadoop编译及MapR ...
- PyQt多窗口调用
经常有人问到如何在一个主窗口中打开一个对话框,然后在确认对话框之后,开启另一个窗口进行后续操作,要求主窗口和最终的窗口之间都能响应用户操作,也就是非模态窗口.随手写了几行代码,简要示意. :::pyt ...
- class int
class int(object): """ int(x=0) -> integer int(x, base=10) -> integer Convert a ...
- 未能加载文件或程序集“Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项。 解决方法
webconfig文件对于oracle的映射错误.需要在以下位置修改 <runtime> <legacyCorruptedStateExceptionsPolicy enabled= ...
- FullCalendar应用——读取JSON数据
开发者可以使用FullCalendar创建强大的日历日程应用,FullCalendar提供了丰富的选项设置和方法调用,使得开发者可以轻松的创建各种功能的日历程序.本文将结合实例使用PHP读取MySQl ...