Aktualizovat „du5/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-09 20:24:07 +00:00
parent 97741f611e
commit 5d515e9080

View File

@ -36,7 +36,7 @@ int main(){
if(str[0]=='\n'){
break;
}
sscanf(str,"%d %s",&score,name);
sscanf(str,"%d %[^\t\n]",&score,name);
PersonList[c].score = score;
strcpy(PersonList[c].name ,name);
c++;
@ -45,10 +45,11 @@ int main(){
if(c>2){
qsort(PersonList,c,sizeof(struct person),comp);
}
int res_strcmp=0;
int idex = 0;
for(int i =0;i<c;i++){
if(strcmp(PersonList[i].name,PersonList[i+1].name)==0){
res_strcmp = strcmp(PersonList[i].name,PersonList[i+1].name);
if(res_strcmp==0){
PersonList[i-idex].score += PersonList[i+1].score;
idex++;
}
@ -61,11 +62,12 @@ int main(){
printf("Vysledok\n");
for(int i =0;i<c;i++){
if(strcmp(PersonList[i].name,PersonList[i+1].name)!=0){
res_strcmp = strcmp(PersonList[i].name,PersonList[i+1].name);
if(res_strcmp!=0){
flag=0;
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
}
else if(strcmp(PersonList[i].name,PersonList[i+1].name)==0&&flag==0){
else if(res_strcmp==0&&flag==0){
flag=1;
printf("%d %s\n",PersonList[i].score,PersonList[i].name);
}