I'm trying to make this URI issue:
Tetris
Your high school class decided to organize a tetris championship. After discussion of the rules, it was defined that each student would play a total of 12 matches. From the 12 scores obtained by a student, the largest and smallest are discarded, and the others are summed, resulting in in the student's final grade.
Since you have programming skills, you have been assigned by the class to write a program to print the classification end of the championship, from the scores of each player. Entry
The input is composed of several test sets. The first line of a set of tests contains an integer J (0 ≤ J ≤ 1000), which indicates the number of players who participated in the championship. Next, for each player there are two lines in the entry: the first one has the name of the player (formed only by letters, being only the initial in with a maximum of 15 letters), and the second has the 12 scores obtained by the player, separated by space. The scores are integers between 0 and 1000. The end of the input is indicated by a test set with J = 0. Output
For each test set, your program should write one line containing the identifier of the test set, in the format "Test n", where n is sequentially numbered from 1. Then your program must write the final classification in the championship, using one line for each participant. Each line must contain three information, separated by a space: the classification of the player, your final score, and your name. The classification of a player is equal to 1 plus the number of players who scored bigger than yours. In case of a tie, players must be sorted alphabetically. After the entire classification, be left blank. The format of the sample output below must be strictly followed.
I am in the part of organizing in alphabetical order those who have the same amount of points. I tried to make a condition in quicksort for when the points are the same, sort by name and am having the following error:
contest.c: In function 'compare': contest.c: 16: 30: error: request for member 'name' in something not a structure or union return strcmp (((Player *) a) .name, (Player *) b) .name); ^ contest.c: 16: 50: error: request for member 'name' in something not a structure or union return strcmp (((Player *) a) .name, (Player *) b) .name);
Can anyone explain what it is? "I've learned it today and I'm kind of doing it blindly. My code is this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char nome[16];
int pontuacao;
}Jogador;
int compare(const void * a, const void * b){
if((*(Jogador *)a).pontuacao > (*(Jogador *)b).pontuacao){
return -1;
}else if((*(Jogador *)a).pontuacao < (*(Jogador *)b).pontuacao){
return 1;
}else if((*(Jogador *)a).pontuacao == (*(Jogador *)b).pontuacao){
return strcmp(((Jogador*)a).nome, ((Jogador*)b).nome);
}
return 0;
}
int achaMaior(int *pontos){
int maior = pontos[0];
int i, j;
for(i = 1; i < 12; i++){
if(pontos[i] > maior){
maior = pontos[i];
}
}
return maior;
}
int achaMenor(int *pontos){
int menor = pontos[0];
int i, j;
for(i = 1; i < 12; i++){
if(pontos[i] < menor){
menor = pontos[i];
}
}
return menor;
}
Jogador jogador[100];
int main(){
int j, i, k , pontos[12], maior, menor, teste = 0;;
scanf("%d", &j);
while(j != 0){
teste++;
for(i = 0; i < j; i++){
scanf("%s", jogador[i].nome);
for(k = 0; k < 12; k++){
scanf("%d", &pontos[k]);
jogador[i].pontuacao += pontos[k];
}
maior = achaMaior(pontos);
menor = achaMenor(pontos);
jogador[i].pontuacao -= (maior + menor);
}
qsort(jogador, j, sizeof(jogador[0]), compare);
printf("Teste %d\n", teste);
for(i = 0; i < j; i++){
printf("%d %d %s\n", i + 1, jogador[i].pontuacao, jogador[i].nome);
}
printf("\n");
for(i = 0; i < j; i++){
jogador[i].pontuacao = 0;
}
scanf("%d", &j);
}
return 0;
}