zoukankan      html  css  js  c++  java
  • 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
    ");
    53             continue;
    54         }
    55         if(flag_st && !flag_pr && !flag_qu)printf("stack
    ");
    56         if(!flag_st && !flag_pr && flag_qu)printf("queue
    ");
    57         if(!flag_st && flag_pr && !flag_qu)printf("priority queue
    ");
    58         if(!flag_st && !flag_pr && !flag_qu)printf("impossible
    ");
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    MyEclipse 9.0 M1 安装 jad 反编译插件
    WPF(二)路由事件5.鼠标拖放
    WPF(二)路由事件2.挂起的事件
    DynamicDataDisplay 不压缩横坐标和图例的修改
    WPF(二)路由事件1.冒泡路由事件
    WPF(二)路由事件3.附加事件
    WPF(三)控件1.概述
    WPF(三)控件2.背景画刷和前景画刷
    WPF(二)路由事件4.隧道路由事件
    WPF(三)控件3.字体
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5989721.html
Copyright © 2011-2022 走看看