-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP144.cpp
54 lines (51 loc) · 1.01 KB
/
P144.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
#include <iostream>
#include <stdio.h>
int main() {
int students[25];
while(true) {
int N, k;
std::cin >> N >> k;
if(N == 0 && k == 0)
return 0;
// GOGOGO!
int store = 1;
int toDispenseI = 1 % k;
for(int i = 0; i < N; ++i) {
students[i] = 0;
}
int studentsLeft = N;
int studentI = 0;
while(true) {
// pay student:
students[studentI] += store;
if(students[studentI] >= 40) {
// kick student:
store = students[studentI]-40;
students[studentI] = 40;
printf("%3i", studentI+1);
--studentsLeft;
if(studentsLeft == 0)
break;
}
else {
store = 0;
}
// update queue:
do {
++studentI;
if(studentI == N)
studentI = 0;
//std::cerr << " Skipping " << studentI <<" N=" <<N << ", left=" << studentsLeft;
}
while(students[studentI] == 40);
// update store:
if(store == 0) {
store = toDispenseI+1;
++toDispenseI;
if(toDispenseI == k)
toDispenseI = 0;
}
}
printf("\n");
}
}