Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define STK 1
- #define PQ 2
- #define QUEUE 3
- int x, pos_in, pos_out, n, in[ 10050 ], out[ 10050 ];
- bool test_queue();
- bool test_stack();
- bool test_priority();
- int main(){
- while( cin >> n ){
- pos_in = pos_out = 0;
- for(int cases = 0; cases < n; cases++){
- cin >> x;
- if(x == 1) cin >> in[ pos_in++ ];
- else cin >> out[ pos_out++ ];
- }
- int a = 0, b = 0, c = 0;
- if( test_queue() ) b = QUEUE;
- if( test_stack() ) c = STK;
- if( test_priority() ) a = PQ;
- if(pos_in == 1 || pos_out == 1)
- a = b = c = 1;
- if(a && b && c)
- cout << "impossible" << endl;
- else if( (a&&b) || (b&&c) || (a&&c) )
- cout << "not sure" << endl;
- else if(a) cout << "priority queue" << endl;
- else if(b) cout << "queue" << endl;
- else if(c) cout << "stack" << endl;
- }
- return 0;
- }
- bool test_stack(){
- for(int i = 0; i < pos_out; i++)
- if(in[i] != out[ pos_in-i-1 ] )
- return false;
- return true;
- }
- bool test_queue(){
- for(int i = 0; i < pos_out; i++)
- if( in[i] != out[i] )
- return false;
- return true;
- }
- bool test_priority(){
- for(int i = 1; i < pos_out; i++)
- if( out[i] > out[i-1])
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement