64 lines
1.3 KiB
C
64 lines
1.3 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 *Personlist = realloc(PersonList,size*sizeof(struct person));
|
|
Personlist[size-1]->score = score;
|
|
strcpy(Personlist[size-1]->name ,name);
|
|
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 main(){
|
|
struct person *PersonList=calloc(0,sizeof(struct person));
|
|
char name[30];
|
|
int score=0;
|
|
int c =0;
|
|
while(scanf("%d %s",&score,name)!=EOF){
|
|
PersonList = addElement(&PersonList,score,name);
|
|
c++;
|
|
}
|
|
|
|
qsort(PersonList,c,sizeof(struct person),comp);
|
|
int idex = 0;
|
|
for(int i =0;i<c;i++){
|
|
if(strcmp(PersonList[i].name,PersonList[i+1].name)==0){
|
|
PersonList[i-idex].score += PersonList[i+1].score;
|
|
idex++;
|
|
}
|
|
else{
|
|
idex=0;
|
|
}
|
|
}
|
|
int flag=0;
|
|
printf("Vysledok\n");
|
|
for(int i =0;i<c;i++){
|
|
if((strcmp(PersonList[i].name,PersonList[i+1].name)==0||strcmp(PersonList[i].name,PersonList[i+1].name)!=0)&&flag==0){
|
|
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
|
|
flag=1;
|
|
}
|
|
else{
|
|
flag=0;
|
|
}
|
|
}
|
|
free(PersonList);
|
|
return 0;
|
|
} |