29 lines
507 B
C
Raw Permalink Normal View History

2023-12-01 13:22:00 +01:00
#include <stdio.h>
#include <stdlib.h>
// Just part 1
2023-12-01 13:22:00 +01:00
int main(int argc, char **argv) {
char c;
int sum = 0;
int first = -1, last = -1;
while ((c = getchar()) != EOF) {
if (c == '\n') {
sum += last != -1 ? first*10 + last : first*10 + first;
first = -1;
last = -1;
} else {
if (c <= '9' && c >= '0') {
if (first == -1) {
first = c - '0';
} else {
last = c - '0';
}
}
}
}
printf("%d\n", sum);
return 0;
}