aboutsummaryrefslogtreecommitdiff
path: root/2023/04/4a.c
diff options
context:
space:
mode:
Diffstat (limited to '2023/04/4a.c')
-rw-r--r--2023/04/4a.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/2023/04/4a.c b/2023/04/4a.c
new file mode 100644
index 0000000..a1f6a9e
--- /dev/null
+++ b/2023/04/4a.c
@@ -0,0 +1,43 @@
1#include <stdbool.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#define N 1000
7
8bool isnum(char c) { return c >= '0' && c <= '9'; }
9
10int main() {
11 char *buf, line[N];
12 int i, j, x, sum, nw, nr, w[100], r[100];
13
14 sum = 0;
15 while ((buf = fgets(line, N, stdin)) != NULL) {
16 nr = nw = 0;
17 while (*buf != ':') buf++;
18 while (*buf != '|') {
19 buf++;
20 if (!isnum(*buf)) continue;
21 w[nw++] = atoi(buf);
22 while (isnum(*buf)) buf++;
23 }
24 while (*buf != '\n') {
25 buf++;
26 if (!isnum(*buf)) continue;
27 r[nr++] = atoi(buf);
28 while (isnum(*buf)) buf++;
29 }
30 for (x = 0, i = 0; i < nr; i++) {
31 for (j = 0; j < nw; j++) {
32 if (r[i] == w[j]) {
33 x++;
34 break;
35 }
36 }
37 }
38 sum += 1 << (x-1);
39 }
40
41 printf("%d\n", sum);
42 return 0;
43}

Generated with cgit - Back to sebastiano.tronto.net