ZOJ 3210 (I)
来源:互联网 发布:bt.gg新域名 编辑:程序博客网 时间:2024/06/03 18:33
#include<iostream>#include<cstdio>#include<string>#include<vector>#include<algorithm>#include<queue>#include<stack>using namespace std;stack<int>s;queue<int>q;int main(){#ifdef CDZSCfreopen("i.txt", "r",stdin);#endifint t,n,x;scanf("%d", &t);while (t--){scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%d", &x);q.push(x);s.push(x);}int ss = 1, qq = 1;for (int i = 0; i < n; i++){scanf("%d", &x);if (q.front() != x){qq = 0;}if (s.top() != x){ss = 0;}s.pop();q.pop();}if (ss&&qq)puts("both");else if (ss)puts("stack");else if (qq)puts("queue");else puts("neither");}return 0;}
直接模拟栈和队列就可以了
Do you know stack and queue? They're both important data structures. A stack is a "first in last out" (FILO) data structure and a queue is a "first in first out" (FIFO) one.
Here comes the problem: given the order of some integers (it is assumed that the stack and queue are both for integers) going into the structure and coming out of it, please guess what kind of data structure it could be - stack or queue?
Notice that here we assume that none of the integers are popped out before all the integers are pushed into the structure.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.
Each test case contains 3 lines: The first line of each test case contains only one integer N indicating the number of integers (1 <= N <= 100). The second line of each test case contains N integers separated by a space, which are given in the order of going into the structure (that is, the first one is the earliest going in). The third line of each test case also contains N integers separated by a space, whick are given in the order of coming out of the structure (the first one is the earliest coming out).
Output
For each test case, output your guess in a single line. If the structure can only be a stack, output "stack"; or if the structure can only be a queue, output "queue"; otherwise if the structure can be either a stack or a queue, output "both", or else otherwise output "neither".
Sample Input
431 2 33 2 131 2 31 2 331 2 11 2 131 2 32 3 1
Sample Output
stackqueuebothneither
Author: CAO, Peng
Source: The 6th Zhejiang Provincial Collegiate Programming Contest
- ZOJ 3210 (I)
- zoj 3911 Prime Query (ZOJ Monthly, October 2015 - I)
- I Think I Need a Houseboat ZOJ(几何计算)
- zoj 3355 Football Gambling I(zoj7月月赛)
- ZOJ 3626 Treasure Hunt I(树型DP+01背包)
- zoj-3626 Treasure Hunt I (树形dp)
- ZOJ 3556 How Many Sets I 解题报告(数论)
- zoj 3626 Treasure Hunt I (树形dp)
- ZOJ 3817 Chinese Knot(牡丹江网络赛I题)
- ZOJ 3556 How Many Sets I (容斥)
- ZOJ 3626 Treasure Hunt I(树形dp)
- ZOJ 3626 Treasure Hunt I (树形dp)
- ZOJ 3687 The Review Plan I(禁位排列)
- Prime Query(ZOJ Monthly, October 2015 - I)
- zoj 3556 How Many Sets I(容斥原理)
- ZOJ 3534 Move the Mouse I (ZOJ Monthly, September 2011 F题)
- ZOJ 4536 ZOJ Monthly, October 2011 I
- [Icpc] zoj 1048 / 1049 I Think I Need a Houseboat (v w)
- 一般的函数
- 杭电2092
- 4. 产品目录概念
- 处理 ActionBarDrawerToggle is Deprecated
- hbase 配置优化(2)
- ZOJ 3210 (I)
- 剑指offer第二十二题【从上往下打印二叉树】c++实现
- 解决tty终端中文乱码
- overflow:hidden
- Java基础:HashMap和HashSet解析
- Qt5中自带串口类QtSerialPort
- servlet输入输出乱码
- ASP.NET MVC Ajax 请求安全
- 利用FFmpeg将RTSP转码成RTMP发布在RED5