-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path31.cpp
62 lines (48 loc) · 1.26 KB
/
31.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
// O(t*c*min(c, p)) with t is number of test cases
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
#include <set>
#include <stack>
#include <numeric>
#include <regex>
#include <queue>
#include <iomanip>
using namespace std;
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
int main() {
FAST_IO;
// FILE_IO;
int p, c, x, cs = 1, f;
char C;
while (true) {
cin >> p >> c; if (p + c == 0) break;
queue<int> q;
for (int i = 1; i <= min(p, c); ++i) q.push(i);
cout << "Case " << cs++ << ":\n";
while (c--) {
cin >> C;
if (C == 'N') {
f = q.front();
cout << q.front() << endl;
q.push(q.front());
q.pop();
} else {
cin >> x;
queue<int> tq;
tq.push(x);
while (!q.empty()) {
f = q.front();
if (f != x) tq.push(f);
q.pop();
}
q.swap(tq);
}
}
}
return 0;
}