84 lines
1.7 KiB
C
84 lines
1.7 KiB
C
#include<stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
struct person{
|
|
int score;
|
|
char name[30];
|
|
};
|
|
/*
|
|
struct person* addElement(struct person **PersonList,int score,char *name){
|
|
static int size = 1;
|
|
struct person *Personlist = calloc(size,sizeof(struct person));
|
|
|
|
size++;
|
|
return Personlist;
|
|
}
|
|
*/
|
|
|
|
int comp(const void *p1, const void *p2){
|
|
struct person* person1 = (struct person*)p1;
|
|
struct person* person2 = (struct person*)p2;
|
|
|
|
return strcmp(person1->name, person2->name);
|
|
}
|
|
|
|
int comp_num(const void *p1, const void *p2){
|
|
struct person* person1 = (struct person*)p1;
|
|
struct person* person2 = (struct person*)p2;
|
|
|
|
return person1->score<person2->score;
|
|
}
|
|
|
|
|
|
int main(){
|
|
struct person PersonList[30];
|
|
char name[30];
|
|
int score=0;
|
|
int c =0;
|
|
char str[100];
|
|
while(fgets(str,100,stdin)){
|
|
if(str[0]=='\n'){
|
|
break;
|
|
}
|
|
sscanf(str,"%d %[^\t\n]",&score,name);
|
|
PersonList[c].score = score;
|
|
strcpy(PersonList[c].name ,name);
|
|
c++;
|
|
}
|
|
|
|
if(c>2){
|
|
qsort(PersonList,c,sizeof(struct person),comp);
|
|
int res_strcmp=0;
|
|
int idex = 0;
|
|
for(int i =0;i<c;i++){
|
|
for(int j = i+1;j<c;j++){
|
|
res_strcmp = strcmp(PersonList[i].name,PersonList[j].name);
|
|
if(res_strcmp==0){
|
|
PersonList[i-idex].score += PersonList[i+1].score;
|
|
idex++;
|
|
c--;
|
|
for (int j=i+1; j<c; j++){
|
|
PersonList[j] = PersonList[j+1];
|
|
}
|
|
}
|
|
else{
|
|
idex=0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
qsort(PersonList,c,sizeof(struct person),comp_num);
|
|
|
|
|
|
|
|
|
|
printf("Vysledky:\n");
|
|
for(int i =0;i<c;i++){
|
|
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
|
|
}
|
|
return 0;
|
|
} |