2020-04-09 18:54:33 +00:00
|
|
|
#include<stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-04-09 19:01:22 +00:00
|
|
|
|
2020-04-09 18:54:33 +00:00
|
|
|
struct person{
|
|
|
|
int score;
|
|
|
|
char name[30];
|
|
|
|
};
|
|
|
|
|
2020-04-09 19:42:01 +00:00
|
|
|
struct person* addElement(struct person **PersonList,int score,char *name){
|
2020-04-09 18:54:33 +00:00
|
|
|
static int size = 1;
|
2020-04-09 19:48:54 +00:00
|
|
|
struct person *Personlist = calloc(size,sizeof(struct person));
|
2020-04-09 19:48:02 +00:00
|
|
|
Personlist[size-1].score = score;
|
|
|
|
strcpy(Personlist[size-1].name ,name);
|
2020-04-09 18:54:33 +00:00
|
|
|
size++;
|
2020-04-09 19:41:19 +00:00
|
|
|
return Personlist;
|
2020-04-09 18:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(){
|
2020-04-09 19:22:20 +00:00
|
|
|
struct person *PersonList=calloc(0,sizeof(struct person));
|
2020-04-09 18:54:33 +00:00
|
|
|
char name[30];
|
|
|
|
int score=0;
|
|
|
|
int c =0;
|
|
|
|
while(scanf("%d %s",&score,name)!=EOF){
|
2020-04-09 19:41:19 +00:00
|
|
|
PersonList = addElement(&PersonList,score,name);
|
2020-04-09 18:54:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 19:01:22 +00:00
|
|
|
int flag=0;
|
2020-04-09 18:54:33 +00:00
|
|
|
printf("Vysledok\n");
|
|
|
|
for(int i =0;i<c;i++){
|
2020-04-09 19:36:08 +00:00
|
|
|
if((strcmp(PersonList[i].name,PersonList[i+1].name)==0||strcmp(PersonList[i].name,PersonList[i+1].name)!=0)&&flag==0){
|
2020-04-09 19:01:22 +00:00
|
|
|
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
|
2020-04-09 19:36:08 +00:00
|
|
|
flag=1;
|
2020-04-09 18:54:33 +00:00
|
|
|
}
|
2020-04-09 19:36:08 +00:00
|
|
|
else{
|
|
|
|
flag=0;
|
|
|
|
}
|
2020-04-09 18:54:33 +00:00
|
|
|
}
|
2020-04-09 19:09:35 +00:00
|
|
|
free(PersonList);
|
2020-04-09 18:54:33 +00:00
|
|
|
return 0;
|
2020-04-09 18:50:31 +00:00
|
|
|
}
|