blob: 9c10b614b54333205464fbee0fbcbe17aa934cef (
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
|
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INPUT_LEN 200
int repair(const int *arr)
{
for (int i = 0; i < INPUT_LEN; i++) {
for (int j = 0; j < INPUT_LEN; j++) {
for (int k = 0; k < INPUT_LEN; k++) {
if (arr[i] + arr[j] + arr[k] == 2020) {
return arr[i] * arr[j] * arr[k];
}
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
FILE *file = fopen(argv[argc - 1], "r");
if (!file) {
return 1;
}
char buffer[8] = { 0 };
int input[INPUT_LEN] = { 0 };
for (int i = 0; i < 200; i++) {
fgets(buffer, 8, file);
input[i] = atoi(buffer);
}
fclose(file);
printf("%i", repair(input));
}
|