aboutsummaryrefslogtreecommitdiff
path: root/2023/01/1b.c
blob: 795571b3f9861e92767afc4f59579bbe64ddbf83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <string.h>

#define N 10000

char *nums[10] = { "zero (unused)", "one", "two", "three", "four", "five",
	"six", "seven", "eight", "nine" };

int main() {
	char *buf, line[N];
	int j, first, last, sum;

	sum = 0;
	while ((buf = fgets(line, N, stdin)) != NULL) {
		for (first = -1; *buf; buf++) {
			for (j = 1; j < 10; j++)
				if (!strncmp(buf, nums[j], strlen(nums[j])))
					*buf = j + '0';
			if (*buf < '0' || *buf > '9') continue;
			first = first == -1 ? *buf - '0' : first;
			last = *buf - '0';
		}
		sum += 10 * first + last;
	}
	printf("%d\n", sum);
	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net