A Stack or A Queue?

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

4
3
1 2 3
3 2 1
3
1 2 3
1 2 3
3
1 2 1
1 2 1
3
1 2 3
2 3 1

Sample Output

stack
queue
both
neither 利用栈和队列的性质判断就好
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define max_v 105
#define eps 10e-6
using namespace std;
int a[max_v];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
int x;
int isque=;
int isstack=;
for(int i=;i<n;i++)
{
scanf("%d",&x);
if(a[i]!=x)
isque=;
if(x!=a[n-i-])
isstack=;
}
if(isque&&isstack)
printf("both\n");
else if(isque==&&isstack==)
printf("queue\n");
else if(isque==&&isstack==)
printf("stack\n");
else if(isque==&&isstack==)
printf("neither\n");
}
return ;
}

ZOJ3202-Second-price Auction(根据输入输出判断是队列还是栈)的更多相关文章

  1. codeforces Rockethon 2015 C Second price auction [想法]

    传送门 C. Second price auction time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. 链表回文串判断&&链式A+B

    有段时间没有练习了,链表回文串判断用到了栈.链式A+B将没有的项用0补充.链表有没有头节点,及结点和链表的区别,即pNode和pHead. //#include<iostream> //u ...

  3. 链表回文串判断&amp;&amp;链式A+B

    有段时间没有练习了,链表回文串判断用到了栈.链式A+B将没有的项用0补充.链表有没有头节点,及结点和链表的区别,即pNode和pHead. //#include<iostream> //u ...

  4. python判断栈的弹出序列是否合法

    参考:https://www.2cto.com/kf/201701/552515.html 数据结构之判断栈的弹出序列是否合法:输入两个整数序列,第一个序列表示栈的压入序列,请判断第二个序列是否为该栈 ...

  5. ECShop函数列表大全

    lib_time.php gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime(hour=NULL ...

  6. ECSHOP二次开发指南

    ECSHOP二次开发指南 发布时间:2013-05-28 12:47:00   来源:   评论:0 点击: 次 [字号:大 中 小] QQ空间新浪微博腾讯微博人人网豆瓣网百度空间百度搜藏开心网复制更 ...

  7. echo二次开发 ecshop 函数列表

    lib_time.php (时间函数) gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime($h ...

  8. ecshop 函数列表大全

    lib_time.phpgmtime() P: 获得当前格林威治时间的时间戳 /$0server_timezone() P: 获得服务器的时区 /$0local_mktime($hour = NULL ...

  9. ABAP技术总结

      SAP ——ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1. 1.1. 1.1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.7.1. 1.7.2. ...

随机推荐

  1. Django基础七之Ajax

    一 Ajax简介 1.简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步的Javascript和XML”.即使用Javascript语言与服务器进行异 ...

  2. iPhone越狱cydia源大全

    越狱后如何添加cydia源及cydia源大全,希望对大家能有所帮助! 工具/原料 cydia 步骤/方法 越狱后添加cydia源 进入Cydia管理中找到软件源,先添加源. 进入“软件源”之后点击右上 ...

  3. npm与gulp的使用

    这边将工作中使用的npm以及gulp的一些方法做了整理,方便以后查阅,至少不用去麻烦度娘了~ A.npm的使用: 1.在你所需要的文件夹里面初始化npm-->  npm init -y    - ...

  4. Python-Image 基本的图像处理操作

    Python-Image 基本的图像处理操作,有需要的朋友可以参考下. Python 里面最常用的图像操作库是 Image library(PIL),功能上,虽然还不能跟Matlab比较,但是还是比较 ...

  5. 使用eclipse遇到的unable to install breakpoint的问题

    调试一个tomcat工程,设置好断点,启动工程,结果出现了下面的错误: 继续运行,再进入断点之前,还会再度提示,但是最终会命中断点. 使用CGLIB查找关键字,了解到CGLIB是一个AOP的拦截库,想 ...

  6. 用于mask遮罩效果的图片配合resizableImage使用

    用于mask遮罩效果的图片配合resizableImage使用 效果: 作为素材用的图片: 源码: // // ViewController.m // Rect // // Created by Yo ...

  7. Google, Facebook, Amazon and Microsoft Salaries

    https://blog.step.com/2016/04/08/an-open-source-project-for-tech-salaries/ Step.com Crowdsource your ...

  8. Composer 的简介、安装及使用

    Composer的简介 简单说,Composer 就是一个安装包管理工具,服务于 PHP 生态系统.它包括了两个部分:Composer 和 Packagist. Composer Composer 是 ...

  9. python2.x和3.x的区别(不定时更新)

    python2.x和3.x的区别 文:铁乐与猫 2018.3.16新增博文,为方便以后总结Python2.x与3.x的不同版本之间的区别,随时更新. python原本的宗旨是崇尚优美.清晰.简单.但p ...

  10. JavaScript基础进阶之常用字符串方法总结

    前面三篇文章简单的把JavaScript基础内容过了一遍,我们已经可以用JavaScript写一些简单的代码了. 今天主要总结一下JavaScript中String对象中自带的一些方法,来帮助我们处理 ...