-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
49 lines (47 loc) · 1.16 KB
/
demo.cpp
File metadata and controls
49 lines (47 loc) · 1.16 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
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <iomanip>
#include <unordered_set>
using namespace std;
int main() {
int t, k, temp, front;
string str;
cin >> t;
auto *que = new queue<int>[1000];
vector<int> check(10000, -1);
vector<int> al(10000);
queue<int> next;
for (int i = 0; i < t; i++) {
cin >> k;
for (int j = 0; j < k; j++) {
cin >> temp;
check[temp] = i;
}
}
while (str != "STOP") {
cin >> str;
if (str == "ENQUEUE") {
cin >> temp;
int lambda = check[temp];
if (lambda >= 0) {
if (!al[lambda]) {
next.push(lambda);
al[lambda] = 1;
}
que[lambda].push(temp);
} else que[t - 1].push(temp);
} else if (str == "DEQUEUE") {
front = next.front();
cout << que[front].front() << " ";
que[front].pop();
if (que[front].empty()) {
al[front] = 0;
next.pop();
}
}
}
delete[] que;
return 0;
}