UVA 1995 I can guess the structer
模 拟
1 /*by SilverN*/ 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<vector> 8 #include<queue> 9 #include<stack> 10 using namespace std; 11 int read(){ 12 int x=0,f=1;char ch=getchar(); 13 while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();} 14 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} 15 return x*f; 16 } 17 priority_queue<int>q; 18 stack<int>st; 19 queue<int>que; 20 int n; 21 int x,y; 22 bool flag_st,flag_qu,flag_pr; 23 int main(){ 24 /* freopen("qu.in","r",stdin); 25 freopen("qu.out","w",stdout);*/ 26 27 while(scanf("%d",&n)!=EOF){ 28 int i,j; 29 flag_pr=flag_qu=flag_st=1; 30 while(!q.empty()) q.pop(); 31 while(!st.empty()) st.pop(); 32 while(!que.empty()) que.pop(); 33 for(i=1;i<=n;i++){ 34 scanf("%d%d",&x,&y); 35 if(x==1){ 36 q.push(y); 37 st.push(y); 38 que.push(y); 39 } 40 else{ 41 if(q.empty() || q.top()!=y)flag_pr=0; 42 if(st.empty() || st.top()!=y)flag_st=0; 43 if(que.empty() || que.front()!=y)flag_qu=0; 44 if(!q.empty())q.pop(); 45 if(!st.empty()) st.pop(); 46 if(!que.empty()) que.pop(); 47 } 48 } 49 int cnt=0; 50 if(flag_st)cnt++; if(flag_pr)cnt++; if(flag_qu)cnt++; 51 if(cnt>1){ 52 printf("not sure\n"); 53 continue; 54 } 55 if(flag_st && !flag_pr && !flag_qu)printf("stack\n"); 56 if(!flag_st && !flag_pr && flag_qu)printf("queue\n"); 57 if(!flag_st && flag_pr && !flag_qu)printf("priority queue\n"); 58 if(!flag_st && !flag_pr && !flag_qu)printf("impossible\n"); 59 } 60 return 0; 61 }
本文为博主原创文章,转载请注明出处。