#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N, M, i, a, b, k, total = 0;
fscanf(stdin, "%d %d", &N, &M);
fprintf(stdout, "N: %d, M: %d\n", N, M);
for(i=0 ; i<M ; i++){
fflush(stdin);
fscanf(stdin, "%d, %d, %d", &a, &b, &k);
fflush(stdout);
fprintf(stdout, "A: %d, B: %d, K: %d\n", a, b, k);
total += (((b-a)+1)*k);
fprintf(stdout, "total: %d\n", total);
}
total = total/N;
fprintf(stdout, "%d\n", total);
return 0;
}
The fscanf(stdin, "%d, %d, %d", &a, &b, &k);
executes for the first time, but didnot execute after that.And even on the first time, only the value of variable a
is correct, for variable b
, and k
are zero. Tried using fflush(stdin)
to clear the stdin before each input, but it didnot work. Please help.
[update from comment:] No I didnot enter a comma.