-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICanGuestTheDataStructure.cpp
58 lines (54 loc) · 1.49 KB
/
ICanGuestTheDataStructure.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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, op, x;
while (cin >> n) {
queue<int> q;
stack<int> s;
priority_queue<int> pq;
bool isS = true, isQ = true, isPQ = true;
for (int i = 0; i < n; i++) {
cin >> op >> x;
switch (op) {
case 1:
if (isS)
s.push(x);
if (isQ)
q.push(x);
if (isPQ)
pq.push(x);
break;
case 2:
if (isS) {
if (s.empty() || s.top() != x)
isS = false;
else
s.pop();
}
if (isQ) {
if (q.empty() || q.front() != x)
isQ = false;
else
q.pop();
}
if (isPQ) {
if (pq.empty() || pq.top() != x)
isPQ = false;
else
pq.pop();
}
break;
}
}
if (isS && !isQ && !isPQ)
cout << "stack" << endl;
else if (!isS && isQ && !isPQ)
cout << "queue" << endl;
else if (!isS && !isQ && isPQ)
cout << "priority queue" << endl;
else if (!isS && !isQ && !isPQ)
cout << "impossible" << endl;
else
cout << "not sure" << endl;
}
}