-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathguessthedatastructure.cc
52 lines (50 loc) · 1.3 KB
/
guessthedatastructure.cc
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
// https://open.kattis.com/problems/guessthedatastructure
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
int main() {
int n;
while (cin >> n) {
stack<int> s;
queue<int> q;
priority_queue<int> pq;
bool is = true, iq = true, ipq = true;
while (n--) {
int a, b;
cin >> a >> b;
if (a == 1) {
s.push(b);
q.push(b);
pq.push(b);
} else {
if (s.empty()) {
is = false;
iq = false;
ipq = false;
} else {
if (s.top() != b) is = false;
if (q.front() != b) iq = false;
if (pq.top() != b) ipq = false;
s.pop();
q.pop();
pq.pop();
}
}
}
int c = 0;
if (is) c++;
if (iq) c++;
if (ipq) c++;
switch (c) {
case 0: cout << "impossible\n"; break;
case 1:
if (is) cout << "stack\n";
else if (iq) cout << "queue\n";
else cout << "priority queue\n";
break;
default:
cout << "not sure\n";
}
}
}