From 554ad47f09974f0131df285fda8ea50a1fdad8f5 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 11 Dec 2023 15:14:47 +0100 Subject: Initial commit, some solutions --- 2023/02/2a.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2023/02/2a.c (limited to '2023/02/2a.c') diff --git a/2023/02/2a.c b/2023/02/2a.c new file mode 100644 index 0000000..f3ddfc8 --- /dev/null +++ b/2023/02/2a.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#define N 10000 + +#define MAX(x, y) ((x)>(y) ? (x) : (y)) + +int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; + +int main() { + char *buf, line[N]; + int i, sum, x, maxc[3]; + + for (i = 1, sum = 0; (buf = fgets(line, N, stdin)) != NULL; i++) { + maxc[0] = maxc[1] = maxc[2] = 0; + while (*buf++ != ':'); + while (*buf++) { + if (*buf < '0' || *buf > '9') + continue; + x = atoi(buf); + while (*buf < 'a' || *buf > 'z') + buf++; + maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); + } + if (maxc[0] <= 12 && maxc[1] <= 13 && maxc[2] <= 14) + sum += i; + } + + printf("%d\n", sum); + return 0; +} -- cgit v1.3