Advertisement
randykaur

arq-maratona

Apr 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define STK 1
  6. #define PQ 2
  7. #define QUEUE 3
  8.  
  9.  
  10. int x, pos_in, pos_out, n, in[ 10050 ], out[ 10050 ];
  11.  
  12. bool test_queue();
  13. bool test_stack();
  14. bool test_priority();
  15.  
  16. int main(){
  17.  
  18. while( cin >> n ){
  19. pos_in = pos_out = 0;
  20.  
  21. for(int cases = 0; cases < n; cases++){
  22. cin >> x;
  23.  
  24. if(x == 1) cin >> in[ pos_in++ ];
  25. else cin >> out[ pos_out++ ];
  26. }
  27.  
  28. int a = 0, b = 0, c = 0;
  29.  
  30. if( test_queue() ) b = QUEUE;
  31. if( test_stack() ) c = STK;
  32. if( test_priority() ) a = PQ;
  33.  
  34. if(pos_in == 1 || pos_out == 1)
  35. a = b = c = 1;
  36.  
  37. if(a && b && c)
  38. cout << "impossible" << endl;
  39. else if( (a&&b) || (b&&c) || (a&&c) )
  40. cout << "not sure" << endl;
  41.  
  42. else if(a) cout << "priority queue" << endl;
  43. else if(b) cout << "queue" << endl;
  44. else if(c) cout << "stack" << endl;
  45. }
  46.  
  47. return 0;
  48.  
  49. }
  50.  
  51. bool test_stack(){
  52. for(int i = 0; i < pos_out; i++)
  53. if(in[i] != out[ pos_in-i-1 ] )
  54. return false;
  55.  
  56. return true;
  57. }
  58.  
  59. bool test_queue(){
  60. for(int i = 0; i < pos_out; i++)
  61. if( in[i] != out[i] )
  62. return false;
  63.  
  64. return true;
  65. }
  66.  
  67. bool test_priority(){
  68. for(int i = 1; i < pos_out; i++)
  69. if( out[i] > out[i-1])
  70. return false;
  71.  
  72. return true;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement