diff options
Diffstat (limited to '2023/02')
| -rw-r--r-- | 2023/02/2a.c | 11 | ||||
| -rw-r--r-- | 2023/02/2b.c | 11 |
2 files changed, 6 insertions, 16 deletions
diff --git a/2023/02/2a.c b/2023/02/2a.c index f3ddfc8..3268cff 100644 --- a/2023/02/2a.c +++ b/2023/02/2a.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 | ||
| 10 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; | 7 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; |
| 11 | 8 | ||
| @@ -17,11 +14,9 @@ int main() { | |||
| 17 | maxc[0] = maxc[1] = maxc[2] = 0; | 14 | maxc[0] = maxc[1] = maxc[2] = 0; |
| 18 | while (*buf++ != ':'); | 15 | while (*buf++ != ':'); |
| 19 | while (*buf++) { | 16 | while (*buf++) { |
| 20 | if (*buf < '0' || *buf > '9') | 17 | if (*buf < '0' || *buf > '9') continue; |
| 21 | continue; | ||
| 22 | x = atoi(buf); | 18 | x = atoi(buf); |
| 23 | while (*buf < 'a' || *buf > 'z') | 19 | while (*buf < 'a' || *buf > 'z') buf++; |
| 24 | buf++; | ||
| 25 | maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); | 20 | maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); |
| 26 | } | 21 | } |
| 27 | if (maxc[0] <= 12 && maxc[1] <= 13 && maxc[2] <= 14) | 22 | if (maxc[0] <= 12 && maxc[1] <= 13 && maxc[2] <= 14) |
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 | ||
| 10 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; | 7 | int 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]; |
