zoukankan      html  css  js  c++  java
  • UVA 11995 I Can Guess the Data Structure!

     //11995 - I Can Guess the Data Structure!
    /*题意:给出输入输出数据判断是那种数据结构
      一种都没有  impossible
      可能是两三种 not ture
      只一种  栈 队列 优先队列
    *///AC关键 :使用bool 函数  ----三个函数何时判断为fales
    #include<cstdio>
    #include<stack>
    #include<queue>
    using namespace std;
    int n;
    int d[1010],p[1010];
    bool istack()
    {
        stack<int>s;
        for(int i=0;i<n;i++)
        {
            if(d[i]==1)s.push(p[i]);//
            else //if(aa[i]==2)
            {
                if(s.empty())  return 0;
                int val;
                val=s.top();s.pop();
                if(p[i]!=val)
                 return 0;
            }
        }
        return 1;
    }
    bool iqueue()
    {
        queue<int>s;
        for(int i=0;i<n;i++)
        {
            if(d[i]==1)s.push(p[i]);
            else  
            {
                if(s.empty())return 0;
                int val;
                val=s.front();s.pop();
                if(p[i]!=val)return 0;
            }
        }return 1;
    }
    bool iprio()
    {
        priority_queue<int > s;
        for(int i=0;i<n;i++)
        {
            if(d[i]==1)s.push(p[i]);
            else  
            {
                if(s.empty())return 0;
                int val;
                val=s.top();s.pop();
                if(p[i]!=val)return 0;
            }
        }
        return 1;
    }
    int main()
    {
        int i,j,k;
        bool a,b,c;
        while(scanf("%d",&n)!=EOF)
        {
            for(i=0;i<n;i++)
            {
                scanf("%d%d",&d[i],&p[i]);
            }
            a=b=c=0;
            a=istack();b=iqueue();c=iprio();
            if(!a&&!b&&!c)printf("impossible\n");
            else  if((!a&&b&&c)||(a&&!b&&c)||(a&&b&&!c)||(a&&b&&c))//两种 或三种
            printf("not sure\n");
            else if(a)printf("stack\n");
            else if(b)printf("queue\n");
            else if(c)printf("priority queue\n");
        }
        return 0;
    }


  • 相关阅读:
    一,初次接触html+css需要注意的小问题
    Pycharm如何在控制台输出窗口中使用Python解释器
    Silver Cow Party POJ
    Constructing Roads POJ
    小希的迷宫 HDU
    Wireless Network POJ
    Scanner读取记事本文件内容为空的解决办法
    mysql limit的使用方法
    Can you find it? HDU-2141 (二分查找模版题)
    【2028-07-18】精力是有限的,但智慧是无限的
  • 原文地址:https://www.cnblogs.com/someonelikeyou/p/2906712.html
Copyright © 2011-2022 走看看