-
Notifications
You must be signed in to change notification settings - Fork 0
/
i_can_guess_the_data_structure.cpp
65 lines (52 loc) · 1.46 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
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int qtd;
while(cin >> qtd){
queue<int> queue;
stack<int> stack;
priority_queue<int> p_queue;
bool q = true, s = true, pq = true;
int op, elem;
while(qtd--){
cin >> op >> elem;
switch (op)
{
case 1:
if(q)
queue.push(elem);
if(s)
stack.push(elem);
if(pq)
p_queue.push(elem);
break;
default:
if(queue.size() == 0 or queue.front() != elem)
q = false;
else
queue.pop();
if(stack.size() == 0 or stack.top() != elem)
s = false;
else
stack.pop();
if(p_queue.size() == 0 or p_queue.top() != elem)
pq = false;
else
p_queue.pop();
break;
}
}
if (!q and !s and !pq)
cout << "impossible" << endl;
else if (q and !s and !pq)
cout << "queue" << endl;
else if (s and !q and !pq)
cout << "stack" << endl;
else if (pq and !q and !s)
cout << "priority queue" << endl;
else
cout << "not sure" << endl;
}
return 0;
}