-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi_can_guess_the_data_structure!.cpp
94 lines (78 loc) · 1.89 KB
/
i_can_guess_the_data_structure!.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <stdio.h>
using namespace std;
int main() {
int n, a, b, aux, popCount;
vector<int> v1, v2;
stack<int> stacker;
queue<int> queuer;
priority_queue<int> priority_queuer;
while (scanf("%d", &n) != EOF) {
v1.clear();
popCount = 0;
aux = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
if (a == 1) {
stacker.push(b);
queuer.push(b);
priority_queuer.push(b);
}
else {
v1.push_back(b);
popCount++;
}
}
for (int i = 0; i < popCount; i++) {
v2.push_back(stacker.top());
stacker.pop();
}
if (v1 == v2) {
aux++;
}
v2.clear();
for (int i = 0; i < popCount; i++) {
v2.push_back(queuer.front());
queuer.pop();
}
if (v1 == v2) {
aux += 2;
}
v2.clear();
for (int i = 0; i < popCount; i++) {
v2.push_back(priority_queuer.top());
priority_queuer.pop();
}
if (v1 == v2) {
aux += 3;
}
v2.clear();
while (!stacker.empty())
stacker.pop();
while (!queuer.empty())
queuer.pop();
while (!priority_queuer.empty())
priority_queuer.pop();
switch (aux) {
case 0:
cout << "impossible\n";
break;
case 1:
cout << "stack\n";
break;
case 2:
cout << "queue\n";
break;
case 3:
cout << "priority queue\n";
break;
default:
cout << "not sure\n";
break;
}
}
return 0;
}