diff options
Diffstat (limited to '2023/04')
| -rw-r--r-- | 2023/04/4a.c | 13 | ||||
| -rw-r--r-- | 2023/04/4b.c | 12 |
2 files changed, 10 insertions, 15 deletions
diff --git a/2023/04/4a.c b/2023/04/4a.c index a1f6a9e..30b7b41 100644 --- a/2023/04/4a.c +++ b/2023/04/4a.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 1000 | 4 | #define N 1000 |
| 7 | 5 | #define ISNUM(c) (c >= '0' && c <= '9') | |
| 8 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 9 | 6 | ||
| 10 | int main() { | 7 | int main() { |
| 11 | char *buf, line[N]; | 8 | char *buf, line[N]; |
| @@ -17,15 +14,15 @@ int main() { | |||
| 17 | while (*buf != ':') buf++; | 14 | while (*buf != ':') buf++; |
| 18 | while (*buf != '|') { | 15 | while (*buf != '|') { |
| 19 | buf++; | 16 | buf++; |
| 20 | if (!isnum(*buf)) continue; | 17 | if (!ISNUM(*buf)) continue; |
| 21 | w[nw++] = atoi(buf); | 18 | w[nw++] = atoi(buf); |
| 22 | while (isnum(*buf)) buf++; | 19 | while (ISNUM(*buf)) buf++; |
| 23 | } | 20 | } |
| 24 | while (*buf != '\n') { | 21 | while (*buf != '\n') { |
| 25 | buf++; | 22 | buf++; |
| 26 | if (!isnum(*buf)) continue; | 23 | if (!ISNUM(*buf)) continue; |
| 27 | r[nr++] = atoi(buf); | 24 | r[nr++] = atoi(buf); |
| 28 | while (isnum(*buf)) buf++; | 25 | while (ISNUM(*buf)) buf++; |
| 29 | } | 26 | } |
| 30 | for (x = 0, i = 0; i < nr; i++) { | 27 | for (x = 0, i = 0; i < nr; i++) { |
| 31 | for (j = 0; j < nw; j++) { | 28 | for (j = 0; j < nw; j++) { |
diff --git a/2023/04/4b.c b/2023/04/4b.c index c122f8b..4529ff7 100644 --- a/2023/04/4b.c +++ b/2023/04/4b.c | |||
| @@ -1,11 +1,9 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdio.h> | 1 | #include <stdio.h> |
| 3 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 4 | #include <string.h> | 3 | #include <string.h> |
| 5 | 4 | ||
| 6 | #define N 1000 | 5 | #define N 1000 |
| 7 | 6 | #define ISNUM(c) (c >= '0' && c <= '9') | |
| 8 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 9 | 7 | ||
| 10 | int main() { | 8 | int main() { |
| 11 | char *buf, line[N]; | 9 | char *buf, line[N]; |
| @@ -19,15 +17,15 @@ int main() { | |||
| 19 | while (*buf != ':') buf++; | 17 | while (*buf != ':') buf++; |
| 20 | while (*buf != '|') { | 18 | while (*buf != '|') { |
| 21 | buf++; | 19 | buf++; |
| 22 | if (!isnum(*buf)) continue; | 20 | if (!ISNUM(*buf)) continue; |
| 23 | w[nw++] = atoi(buf); | 21 | w[nw++] = atoi(buf); |
| 24 | while (isnum(*buf)) buf++; | 22 | while (ISNUM(*buf)) buf++; |
| 25 | } | 23 | } |
| 26 | while (*buf != '\n') { | 24 | while (*buf != '\n') { |
| 27 | buf++; | 25 | buf++; |
| 28 | if (!isnum(*buf)) continue; | 26 | if (!ISNUM(*buf)) continue; |
| 29 | r[nr++] = atoi(buf); | 27 | r[nr++] = atoi(buf); |
| 30 | while (isnum(*buf)) buf++; | 28 | while (ISNUM(*buf)) buf++; |
| 31 | } | 29 | } |
| 32 | for (x = 0, i = 0; i < nr; i++) { | 30 | for (x = 0, i = 0; i < nr; i++) { |
| 33 | for (j = 0; j < nw; j++) { | 31 | for (j = 0; j < nw; j++) { |
