博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(hdu step 8.1.1)ACboy needs your help again!(STL中栈和队列的基本使用)
阅读量:6655 次
发布时间:2019-06-25

本文共 2485 字,大约阅读时间需要 8 分钟。

题目:

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
44 FIFOIN 1IN 2OUTOUT4 FILOIN 1IN 2OUTOUT5 FIFOIN 1IN 2OUTOUTOUT5 FILOIN 1IN 2OUTIN 3OUT
 
Sample Output
122112None23
 
 
Source
2007省赛集训队练习赛(1)
 
Recommend
lcy

题目分析:

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

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

。哎哎。。

代码例如以下:

/* * a.cpp * 栈和队列的模拟 * *  Created on: 2015年3月19日 *      Author: Administrator */#include 
#include
#include
#include
using namespace std;int main(){ int t; scanf("%d",&t); while(t--){ int n; string type; cin >> n >> type; if(type == "FIFO"){ queue
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
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;}

转载地址:http://tzxto.baihongyu.com/

你可能感兴趣的文章
nf_conntrack: table full, dropping packet
查看>>
Linux的五个查找命令:find,locate,whereis,which,type
查看>>
KK课表抓取教务系统
查看>>
mac上如何某端口号被哪些程序占用
查看>>
mac 随记
查看>>
易宝典文章——玩转Office 365中的Exchange Online服务 之二十四 配置垃圾邮件筛选器反垃圾邮件...
查看>>
读写者锁与生产者/消费者模式
查看>>
关于python中的if __name__=='__main__'语句问题
查看>>
Nagios 实现多台监控
查看>>
节约时间的18种方法
查看>>
Debian下搭建zabbix监控
查看>>
中行安全控件可致 Win8 笔记本键盘失灵
查看>>
病毒与***的查杀
查看>>
线程组
查看>>
涉密数据的处理
查看>>
我的友情链接
查看>>
【单机实现系列】通过scom2012对Hyper-V主机来监控和邮件报警②
查看>>
16.文件系统——软RAID的实现(三)(RAID5、装配RAID、JBOD)
查看>>
python简介
查看>>
python字典开发三级菜单
查看>>