blob: 43dd7865fba669a829a43ab57ff7150e79feb133 (
plain) (
blame)
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
|
#include <stdio.h>
#include <stdlib.h>
typedef unsigned uint;
int main() {
uint steps = 0;
uint deps[26] = {0};
while (!feof(stdin)) {
char dep, step;
scanf(
"Step %c must be finished before step %c can begin.\n",
&dep, &step
);
deps[step - 'A'] |= 1 << (dep - 'A');
}
while (steps != (1 << 26) - 1) {
for (uint i = 0; i < 26; ++i) {
if (steps & (1 << i)) continue;
if ((deps[i] & steps) != deps[i]) continue;
printf("%c", 'A' + i);
steps |= (1 << i);
break;
}
}
printf("\n");
}
|