风言枫语  
/*
 * 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;
}


posted on 2013-10-31 21:13  风言枫语  阅读(231)  评论(0编辑  收藏  举报