Aktualizovat „du5/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-09 20:12:45 +00:00
parent 9ba158588e
commit 97741f611e

View File

@ -7,16 +7,15 @@ 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));
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;
@ -28,16 +27,25 @@ int comp(const void *p1, const void *p2){
int main(){
struct person *PersonList=calloc(0,sizeof(struct person));
struct person PersonList[30];
char name[30];
int score=0;
int c =0;
while(scanf("%d %s",&score,name)!=EOF){
PersonList = addElement(&PersonList,score,name);
char str[100];
while(fgets(str,100,stdin)){
if(str[0]=='\n'){
break;
}
sscanf(str,"%d %s",&score,name);
PersonList[c].score = score;
strcpy(PersonList[c].name ,name);
c++;
}
qsort(PersonList,c,sizeof(struct person),comp);
if(c>2){
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){
@ -48,17 +56,20 @@ int main(){
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){
if(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;
}
else if(strcmp(PersonList[i].name,PersonList[i+1].name)==0&&flag==0){
flag=1;
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
}
}
free(PersonList);
return 0;
}