aboutsummaryrefslogtreecommitdiff
path: root/2023/01/1a.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-12-11 15:14:47 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-12-11 15:14:47 +0100
commit554ad47f09974f0131df285fda8ea50a1fdad8f5 (patch)
treed23caeb85e7fce6290664a0ebf3c96f513efbe94 /2023/01/1a.c
downloadaoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.tar.gz
aoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.zip
Initial commit, some solutions
Diffstat (limited to '2023/01/1a.c')
-rw-r--r--2023/01/1a.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/2023/01/1a.c b/2023/01/1a.c
new file mode 100644
index 0000000..0983236
--- /dev/null
+++ b/2023/01/1a.c
@@ -0,0 +1,21 @@
1#include <stdio.h>
2
3#define N 10000
4
5int main() {
6 char *buf, line[N];
7 int first, last, sum;
8
9 sum = 0;
10 while ((buf = fgets(line, N, stdin)) != NULL) {
11 for (first = -1; *buf; buf++) {
12 if (*buf < '0' || *buf > '9')
13 continue;
14 first = first == -1 ? *buf - '0' : first;
15 last = *buf - '0';
16 }
17 sum += 10 * first + last;
18 }
19 printf("%d\n", sum);
20 return 0;
21}

Generated with cgit - Back to sebastiano.tronto.net