(队列的应用5.3.1)ZOJ 3210 A Stack or A Queue?根据进入结构的序列和离开结构的序列确定是stack还是queue)
/* * ZOJ_3210.cpp * * Created on: 2013年10月30日 * Author: Administrator */#include <iostream>#include <cstdio>using namespace std;const int maxn = 110;int main(){ int a[maxn];int t;scanf("%d",&t);while(t--){bool isstack = true,isqueue = true;int n;scanf("%d",&n);int i;for(i = 0 ; i < n ; ++i){scanf("%d",&a[i]);}for(i = 0 ; i < n ; ++i){int b;scanf("%d",&b);if( b != a[i]){//判断是否满足先进先出isqueue = false;}if(b != a[n - 1 - i]){//判断是否满足先进后出isstack = false;}}if(isstack && isqueue){printf("both\n");}else if(!isstack && !isqueue){printf("neither\n");}else if(isstack){printf("stack\n");}else if(isqueue){printf("queue\n");}}return 0;}