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 }
  • 相关阅读:
    php文件hash算法,秒传原理
    pytest-2:allure 的安装、使用
    python操作数据库(Mysql)
    python中OS常用方法
    Selenium2+python-unittest之装饰器(@classmethod)
    selenium中嵌套iframe的切换
    selenium3驱动IE浏览器设置
    selenium测试报告(含通过率统计图和失败截图)
    python3打包成exe---pyinstaller方法
    Python2图像文本识别
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5989721.html
Copyright © 2011-2022 走看看