-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1340.cpp
64 lines (57 loc) · 1.17 KB
/
1340.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
stack<int> s;
queue<int> q;
priority_queue <int, vector<int>, less<int> > pq;
int n;
int op;
int result;
int it_pq;
int it_stack;
int it_queue;
while(cin >> n)
{
it_pq = 1;
it_stack = 1;
it_queue = 1;
for (int i = 0; i < n; i++)
{
cin >> op >> result;
if (op == 1)
{
if (it_stack) s.push(result);
if (it_queue) q.push(result);
if (it_pq) pq.push(result);
}
else
{
if (s.top() == result)
s.pop();
else it_stack = 0;
if (q.front() == result)
q.pop();
else it_queue = 0;
if (pq.top() == result)
pq.pop();
else it_pq = 0;
}
}
if (it_stack && !it_queue && !it_pq)
cout << "stack\n";
else if (!it_stack && it_queue && !it_pq)
cout << "queue\n";
else if (!it_stack && !it_queue && it_pq)
cout << "priority queue\n";
else if (it_stack || it_queue || it_pq)
cout << "not sure\n";
else if (!it_stack && !it_queue && !it_pq)
cout << "impossible\n";
while(!s.empty()) s.pop();
while(!q.empty()) q.pop();
while(!pq.empty()) pq.pop();
}
return 0;
}