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/2b.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2023/02/2b.c (limited to '2023/02/2b.c') diff --git a/2023/02/2b.c b/2023/02/2b.c new file mode 100644 index 0000000..1b30114 --- /dev/null +++ b/2023/02/2b.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 sum, x, maxc[3]; + + sum = 0; + while ((buf = fgets(line, N, stdin)) != NULL) { + 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); + } + sum += maxc[0] * maxc[1] * maxc[2]; + } + + printf("%d\n", sum); + return 0; +} -- cgit v1.3