-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA-11995.cpp
More file actions
59 lines (53 loc) · 1.18 KB
/
UVA-11995.cpp
File metadata and controls
59 lines (53 loc) · 1.18 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, cmd, fila = 0, pilha = 0, filap = 0;
ll resp = 4;
// 1 stack
// 2 queue
// 3 priority_queue
// 4 impossible
// 5 not sure
while(cin >> n){
priority_queue<ll> pq;
queue<ll> q;
stack<ll> s;
int total = 0;
resp = 4;
fila = 0, pilha = 0, filap = 0;
for(ll i = 0; i < n; i++){
ll temp;
cin >> cmd >> temp;
if(cmd == 1){
pq.push(temp);
q.push(temp);
s.push(temp);
}else{
total++;
if(!pq.empty()) if(temp == pq.top()) filap++;
if(!q.empty()) if(temp == q.front()) fila++;
if(!s.empty()) if(temp == s.top()) pilha++;
if(!pq.empty()) pq.pop();
if(!q.empty()) q.pop();
if(!s.empty()) s.pop();
}
}
//cout << filap << " " << fila << " " << pilha << endl;
if(filap == total) resp = 3;
if(fila == total){
if(resp == 4) resp = 2;
else resp = 5;
}
if(pilha == total){
if(resp == 4) resp = 1;
else resp = 5;
}
if(resp == 1) cout << "stack\n";
else if(resp == 2) cout << "queue\n";
else if(resp == 3) cout << "priority queue\n";
else if(resp == 4) cout << "impossible\n";
else cout << "not sure\n";
}
return 0;
}