Stavo risolvendo Improving Grades (grades) e ho scritto un codice che ottiene solamente 30/100.
Il codice in questione:
/*
* This template is valid both in C and in C++,
* so you can expand it with code from both languages.
* NOTE: it is recommended to use this even if you don't
* understand the following code.
*/
#include <stdio.h>
#include <assert.h>
// constraints
#define MAXN 20
// input data
int N;
int G[MAXN];
int main() {
// uncomment the following lines if you want to read/write from files
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int result=-1, prev=0, temp;
assert(1 == scanf("%d", &N));
for(int i=0; i<N; i++){
assert(1 == scanf("%d", &G[i]));
}
int i, j;
for(i=0; i<N&&G[i]>=6; i++){}
for(j=N-1; j>=0&&G[j]<6; j--){}
printf("%d\n", (j-i>0 ? j-i+1 : -1)); // print the result
return 0;
}
Mi sento di aver dimenticato qualcosa di palesissimo, e non riesco a notarlo, qualcuno mi aiuterebbe?