diff options
Diffstat (limited to '2023/05/5a.c')
| -rw-r--r-- | 2023/05/5a.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/2023/05/5a.c b/2023/05/5a.c new file mode 100644 index 0000000..15d2805 --- /dev/null +++ b/2023/05/5a.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | #include <inttypes.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | #define N 100 | ||
| 8 | |||
| 9 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 10 | |||
| 11 | int main() { | ||
| 12 | char *buf, line[N]; | ||
| 13 | int64_t i, m, ns, seed[N], next[N], r[3]; | ||
| 14 | |||
| 15 | for (ns = 0, buf = fgets(line, N, stdin); *buf; buf++) { | ||
| 16 | if (!isnum(*buf)) continue; | ||
| 17 | next[ns++] = atoll(buf); | ||
| 18 | while (isnum(*buf)) buf++; | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | while ((buf = fgets(line, N, stdin)) != NULL) { | ||
| 23 | if (!isnum(*buf)) { | ||
| 24 | memcpy(seed, next, ns * sizeof(int64_t)); | ||
| 25 | fgets(line, N, stdin); /* Discard description */ | ||
| 26 | continue; | ||
| 27 | } | ||
| 28 | |||
| 29 | for (i = 0; *buf; buf++) { | ||
| 30 | r[i++] = atoll(buf); | ||
| 31 | while (isnum(*buf)) buf++; | ||
| 32 | } | ||
| 33 | |||
| 34 | for (i = 0; i < ns; i++) | ||
| 35 | if (seed[i] >= r[1] && seed[i] < r[1] + r[2]) | ||
| 36 | next[i] = seed[i] + (r[0] - r[1]); | ||
| 37 | } | ||
| 38 | |||
| 39 | m = next[0]; | ||
| 40 | for (i = 1; i < ns; i++) | ||
| 41 | m = m > next[i] ? next[i] : m; | ||
| 42 | |||
| 43 | printf("%" PRId64 "\n", m); | ||
| 44 | return 0; | ||
| 45 | } | ||
