-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-12_problem1.c
37 lines (34 loc) · 932 Bytes
/
01-12_problem1.c
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
#include <stdio.h>
#include <stdlib.h>
#define BufferSize 512
#define MAX_SIZE 100
int main(){
FILE *p;
char string[BufferSize];
int num[MAX_SIZE], i = 0, value, j, sum, maxValue = 0, record = 0 , k = 0;
p = fopen("01-12_input.txt", "r");
while (!feof(p)){
value = 0;
fgets(string,BufferSize, p);
sscanf(string, "%d", &value);
/*printf("%d: %d\n", i, value);*/
num[i] = value;
i++;
/*Could be optimizated suming on interation and only checking on this if*/
if(value == 0){
sum = 0;
for(j = 0; j < i; j++){
sum += num[j];
}
i = 0;
k++;
if (maxValue < sum){
maxValue = sum;
record = k;
}
}
}
fclose(p);
printf("%d: %d\n", record, maxValue);
return 0;
}