blob: 9d7f357c69d91b0258f7d0ab6caa970e98d81837 (
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
|
#include <stdio.h>
#include <stdlib.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;
}
|