aboutsummaryrefslogtreecommitdiff
path: root/2023/02/2b.c
blob: 1b30114d1c003e63df42b2a38764b3886ad7cf4c (plain)
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
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#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;
}

Generated with cgit - Back to sebastiano.tronto.net