blob: be73968119c418e83c62306ca46a0ab5ff4b93d2 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <stdio.h>
#include <string.h>
#include <algds/str.h>
#include <algds/vec.h>
void getlines(StringVector *lines) {
while (1) {
char *line = fgetline(stdin);
if (line == NULL) {
break;
}
StringVector_push_back(lines, line);
}
}
int find_max(const char *line) {
int len = strlen(line);
int max = 0;
for (int i = 0; i < len - 1; i++) {
for (int j = i + 1; j < len; j++) {
int n = (line[i] - '0') * 10 + line[j] - '0';
if (n > max) {
max = n;
}
}
}
return max;
}
int main() {
StringVector lines;
StringVector_init(&lines);
getlines(&lines);
String *it = StringVector_begin(&lines);
int sum = 0;
for (; it != StringVector_end(&lines); it++) {
sum += find_max(*it);
}
printf("%d\n", sum);
return 0;
}
|