Aktualizovat „du5/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-09 19:01:22 +00:00
parent f2a7087010
commit bfac43403d

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct person{ struct person{
int score; int score;
char name[30]; char name[30];
@ -9,7 +10,7 @@ struct person{
void addElement(struct person* PersonList,int score,char *name){ void addElement(struct person* PersonList,int score,char *name){
static int size = 1; static int size = 1;
PersonList = realloc(PersonList,size*sizeof(struct person); PersonList = realloc(PersonList,size*sizeof(struct person));
PersonList[size-1]->score = score; PersonList[size-1]->score = score;
PersonList[size-1]->name = name; PersonList[size-1]->name = name;
size++; size++;
@ -32,7 +33,7 @@ int main(){
int score=0; int score=0;
int c =0; int c =0;
while(scanf("%d %s",&score,name)!=EOF){ while(scanf("%d %s",&score,name)!=EOF){
addElement(&PersonList,score,name); addElement(PersonList,score,name);
c++; c++;
} }
@ -47,11 +48,11 @@ int main(){
idex=0; idex=0;
} }
} }
int flag=0;
printf("Vysledok\n"); printf("Vysledok\n");
for(int i =0;i<c;i++){ for(int i =0;i<c;i++){
if(strcmp(PersonList[i].name,PersonList[i+1].name)!=0){ if(strcmp(PersonList[i].name,PersonList[i+1].name)!=0||flag==0){
printf("%d %s\n",PersonList.score,PersonList.name); printf("%d %s\n",PersonList[i].score,PersonList[i].name);
} }
} }