水题,栈和队列处理一下就好,
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int ans;
int b[205];
#include <queue>
#include <stack>
int main()
{
char s[305][305];
char s1[305];
int i,j;
int n,m;
int ans=0;
int t;
int flag,flag1;
cin>>t;
while(t--)
{
queue<int>q;
stack<int >Q;
int n;
cin>>n;
for(i=0; i<n; i++)
{
scanf("%d",&m);
q.push(m);
Q.push(m);
}
flag=1;
flag1=1;
for(i=0; i<n; i++)
{
scanf("%d",&m);
if(m!=q.front())
flag=0;
if(m!=Q.top())
flag1=0;
q.pop();
Q.pop();
}
if(flag &&flag1)
{
cout<<"both"<<endl;
}
else if(flag &&!flag1)
{
cout<<"queue"<<endl;
}
else if(!flag &&flag1)
{
cout<<"stack"<<endl;
}
else
cout<<"neither"<<endl;
}
}