aboutsummaryrefslogtreecommitdiff
path: root/2023/02/2b.c
diff options
context:
space:
mode:
Diffstat (limited to '2023/02/2b.c')
-rw-r--r--2023/02/2b.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/2023/02/2b.c b/2023/02/2b.c
index 1b30114..9d7f357 100644
--- a/2023/02/2b.c
+++ b/2023/02/2b.c
@@ -1,11 +1,8 @@
1#include <stdbool.h>
2#include <stdio.h> 1#include <stdio.h>
3#include <stdlib.h> 2#include <stdlib.h>
4#include <string.h>
5 3
6#define N 10000 4#define N 10000
7 5#define MAX(x,y) ((x)>(y)?(x):(y))
8#define MAX(x, y) ((x)>(y) ? (x) : (y))
9 6
10int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; 7int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 };
11 8
@@ -18,11 +15,9 @@ int main() {
18 maxc[0] = maxc[1] = maxc[2] = 0; 15 maxc[0] = maxc[1] = maxc[2] = 0;
19 while (*buf++ != ':'); 16 while (*buf++ != ':');
20 while (*buf++) { 17 while (*buf++) {
21 if (*buf < '0' || *buf > '9') 18 if (*buf < '0' || *buf > '9') continue;
22 continue;
23 x = atoi(buf); 19 x = atoi(buf);
24 while (*buf < 'a' || *buf > 'z') 20 while (*buf < 'a' || *buf > 'z') buf++;
25 buf++;
26 maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); 21 maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x);
27 } 22 }
28 sum += maxc[0] * maxc[1] * maxc[2]; 23 sum += maxc[0] * maxc[1] * maxc[2];

Generated with cgit - Back to sebastiano.tronto.net