The 6th Zhejiang Provincial Collegiate Programming Contest->Problem I:A Stack or A Queue?

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3210

题意:给出stack和queue的定义,一个是先进后出(FILO),一个是先进先出(FIFO),每个样例都有两行,每行n个,判断它们的属性。(我每次都是用最笨的方法。。)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     int t,n,k,r,h,i,j;
 5     int a[2][250];
 6     cin>>t;
 7     while(t--) {
 8         cin>>n;
 9         k=1,r=1;
10         for(i=0; i<2; i++)
11             for(j=0; j<n; j++)
12                 cin>>a[i][j];
13         for(i=0,j=0,h=n-1; j<n,h>=0; j++,h--) {
14             if(a[i][j]!=a[i+1][h])
15                 k=0;
16         }
17         for(j=0,i=0; j<n; j++) {
18             if(a[i][j]!=a[i+1][j])
19                 r=0;
20         }
21         if(k&&!r)
22             printf("stack
");
23         else if(r&&!k)
24             printf("queue
");
25         else if(k&&r)
26             printf("both
");
27         else
28             printf("neither
");
29     }
30     return 0;
31 }
我会一直在
原文地址:https://www.cnblogs.com/zhien-aa/p/5220160.html