1
#include <stdio.h>
struct tetris{
char nome[16];
int pontuacao;
};
int main(){
int i, nteste = 1, J, k, total = 0, maior, menor, pontos;
while (scanf("%d\n", &J) && J != 0){
struct tetris jogador[J];
for (i = 0; i < J; i++){
fgets(jogador[i].nome, 16, stdin);
printf("LI NOME");
total = 0;
maior = 0;
for (k = 0; k <= 11; k++){
if (k == 11)
scanf("%d\n", &pontos);
else
scanf("%d", &pontos);
printf("LI PONTO");
total += pontos;
if (pontos > maior)
maior = pontos;
else
if (pontos < menor)
menor = pontos;
if (k == 0)
menor = maior;
}
jogador[i].pontuacao = total - maior - menor;
}
printf("ACABEI");
for (k = 0; k < J; k++){
printf("%s %d", jogador[k].nome, jogador[k].pontuacao);
}
}
return 0;
}
After I type in all the data, like this, for example:
4
Zezinho
100 123 133 333 400 300 129 200 360 340 200 600
Luizinho
60 50 120 250 170 190 190 220 260 270 290 300
Carlinhos
10 10 20 10 10 10 10 20 20 20 20 20
Joaozinho
200 300 400 400 500 500 500 600 650 650 700 810
4 is equivalent to the number of players, the strings to their respective names and the integers to the scores. After typing them, my (incomplete) code should print the names and scores, but instead, it asks for reading one more value, which I have no idea what it is.
I’ve tried to use gets
, scanf
, and now the fgets
- thinking that the error was in the reading of the strings - but it did not work.
What has been causing this? Why at the end of the test case he asks for an additional value?
Thanks for your time, buddy. while runs the program while the user does not type a J = 0, that is, when he type 0, the program terminates - it is a requirement of the site. The problem is not in the stopping condition of the readings, but in the amount of readings that the system is asking, always +1 of what it should. (Within each test case, at the end)
– Felipe Nunes
If I do this, the program will be incorrect, because the site says "0 <= J <= 1000 (J = 0 only to indicate final of the entry)"
– Felipe Nunes
Beauty. Just to try to clarify the problem: Instead of typing this: 2 Carlos 1 2 3 4 5 6 7 8 9 10 11 12 João 2 3 4 5 6 7 8 9 10 11 12 John 1 2 3 4 5 6 7 8 9 10 11 12 X Where X can be anything, an integer or a character.
– Felipe Nunes
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero