ghorardim

uva 11995

Nov 3rd, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<ctype.h>
  5. #include<stdlib.h>
  6. #include<cstdio>
  7. #include<cstring>
  8. #include<string>
  9. #include<cmath>
  10. #include<iostream>
  11. #include<cctype>
  12. #include<map>
  13. #include<stack>
  14. #include<cstdlib>
  15. #include <queue>
  16. #include <vector>
  17. #include<algorithm>
  18.  
  19.  
  20. using namespace std;
  21. typedef long int LD;
  22. typedef long long int LLD;
  23. typedef float F;
  24. typedef double LF;
  25. typedef unsigned int U;
  26. typedef unsigned long int LU;
  27. typedef unsigned long long int LLU;
  28. typedef char C;
  29.  
  30. #define sf scanf
  31. #define pf printf
  32. #define PI acos(-1.0)
  33. #define sq(x) (x)*(x)
  34. #define MAX(x,y) (x>y)?x:y
  35. #define MIN(x,y) (x<y)?x:y
  36. #define MAX3(x,y,z) (x>y)?((x>z)?x:z):((y>z)?((y>x)?y:x):z)
  37. #define MIN3(x,y,z) (x<y)?((x<z)?x:z):((y<z)?((y<x)?y:x):z)
  38. #define nn printf("\n")
  39. //#define sz 1005
  40.  
  41. /******   start your code   *******/
  42.  
  43. int main()
  44. {
  45.     int n,a,b,i,nt,im,q,p,s,coun;
  46.     while(sf("%d",&n)!=EOF)
  47.     {
  48.         queue<int>qu;
  49.         priority_queue<int>pqu;
  50.         stack<int>stk;
  51.         nt=im=q=p=s=coun=0;
  52.         for(i=0; i<n; i++)
  53.         {
  54.             sf("%d%d",&a,&b);
  55.             switch(a)
  56.             {
  57.             case 1:
  58.             {
  59.                 qu.push(b);
  60.                 pqu.push(b);
  61.                 stk.push(b);
  62.             }
  63.             break;
  64.             case 2:
  65.             {
  66.                 int x,y,z;
  67.                 x=y=z=102;
  68.                 coun++;
  69.                 if(!qu.empty())
  70.                 {
  71.                     x=qu.front();
  72.                     qu.pop();
  73.                 }
  74.                 if(!pqu.empty())
  75.                 {
  76.                     y=pqu.top();
  77.                     pqu.pop();
  78.                 }
  79.                 if(!stk.empty())
  80.                 {
  81.                     z=stk.top();
  82.                     stk.pop();
  83.                 }
  84.                 if((x==b && y==b)||(x==b && z==b)|| (z==b && y==b))
  85.                     nt++;
  86.                 if(x==b)
  87.                     q++;
  88.                 if(y==b)
  89.                     p++;
  90.                 if(z==b)
  91.                     s++;
  92.                 if(x!=b && y!=b && z!=b)
  93.                     im++;
  94.             }
  95.                 //break;
  96.             }
  97.         }
  98.         if(nt==coun)
  99.             pf("not sure\n");
  100.         else if(q==coun)
  101.             pf("queue\n");
  102.         else if(p==coun)
  103.             pf("priority queue\n");
  104.         else if(s==coun)
  105.             pf("stack\n");
  106.         else if(im==coun)
  107.             pf("impossible\n");
  108.         else
  109.             pf("impossible\n");
  110.     }
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment