UVA 1995 I can guess the structer

Posted SilverNebula

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于UVA 1995 I can guess the structer的主要内容,如果未能解决你的问题,请参考以下文章

Uva 11995 I Can Guess the Data Structure!

UVA11995 I Can Guess the Data Structure!

UVa 11995 - I Can Guess the Data Structure!

uva 11995 I Can Guess the Data Structure!

B - I Can Guess the Data Structure!(建议使用栈队列和优先队列来模拟)

UVA - 1423 Guess(拓扑排序)