Aktualizovat „du5/program.c“
This commit is contained in:
		
							parent
							
								
									2e4df70c5d
								
							
						
					
					
						commit
						5be95e0e42
					
				@ -21,7 +21,7 @@ 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);
 | 
			
		||||
	return strcmp(person1->name, person2->name)>0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int comp_num(const void *p1, const void *p2){
 | 
			
		||||
@ -49,31 +49,38 @@ int main(){
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if(c>2){
 | 
			
		||||
	    qsort(PersonList,c,sizeof(struct person),comp);
 | 
			
		||||
	qsort(PersonList,c,sizeof(struct person),comp);
 | 
			
		||||
	int res_strcmp=0;
 | 
			
		||||
	int idex = 0;
 | 
			
		||||
	for(int i =0;i<c;i++){
 | 
			
		||||
	    for(int j = i+1;j<c;j++){
 | 
			
		||||
	         res_strcmp = strcmp(PersonList[i].name,PersonList[j].name);
 | 
			
		||||
	    	if(res_strcmp==0){
 | 
			
		||||
			    PersonList[i-idex].score += PersonList[i+1].score;
 | 
			
		||||
                idex++;
 | 
			
		||||
                c--;
 | 
			
		||||
		    	for (int j=i+1; j<c; j++){ 
 | 
			
		||||
                    PersonList[j] = PersonList[j+1]; 
 | 
			
		||||
                } 
 | 
			
		||||
		    }	
 | 
			
		||||
		    else{
 | 
			
		||||
		    	idex=0;
 | 
			
		||||
		    }
 | 
			
		||||
	   }
 | 
			
		||||
	}
 | 
			
		||||
	    res_strcmp = strcmp(PersonList[i].name,PersonList[i+1].name);
 | 
			
		||||
	    if(res_strcmp==0){
 | 
			
		||||
		    PersonList[i-idex].score += PersonList[i+1].score;
 | 
			
		||||
            idex++;
 | 
			
		||||
		}	
 | 
			
		||||
		else{
 | 
			
		||||
		  	idex=0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	}	
 | 
			
		||||
	
 | 
			
		||||
	//int flag=0;
 | 
			
		||||
    qsort(PersonList,c,sizeof(struct person),comp_num);
 | 
			
		||||
    int k =0;
 | 
			
		||||
    
 | 
			
		||||
  
 | 
			
		||||
   
 | 
			
		||||
  for(int i =0;i<c-1;i++){
 | 
			
		||||
       for(int j=i+1;j<c-1-i;j++){
 | 
			
		||||
            if(strcmp(PersonList[i].name,PersonList[j].name)==0&&PersonList[i].score>PersonList[j].score){
 | 
			
		||||
                    struct person temp = PersonList[j];
 | 
			
		||||
                    PersonList[j] = PersonList[j+1];
 | 
			
		||||
                    PersonList[j+1]=temp;
 | 
			
		||||
                    c--;
 | 
			
		||||
            }
 | 
			
		||||
       }
 | 
			
		||||
       
 | 
			
		||||
   }
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
	printf("Vysledky:\n");
 | 
			
		||||
@ -81,4 +88,4 @@ int main(){
 | 
			
		||||
	    printf("%d %s\n",PersonList[i].score,PersonList[i].name);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user