From 2377dc324ce89ef4b40f4b701920043716f9e36b Mon Sep 17 00:00:00 2001 From: Artem Horbunov Date: Tue, 7 Apr 2020 15:15:09 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu5/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du5/program.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/du5/program.c b/du5/program.c index 72ccbdc..befd007 100644 --- a/du5/program.c +++ b/du5/program.c @@ -5,6 +5,7 @@ int main(){ char name[50][50]; int score[50]; int pos = 0; + //Getting input while(1){ scanf("%d %[^\n]", &score[pos], name[pos]); scanf("%*c"); @@ -18,6 +19,7 @@ int main(){ int newScore[50]; int newPos = 0; + //Combining names for(int i = 0; i < pos; i++){ int check = 0; for(int q = 0; q < newPos; q++){ @@ -35,15 +37,22 @@ int main(){ } } + //Combining scores for(int i = 0; i < newPos; i++){ for(int q = 0; q < pos; q++){ if(strcmp(newName[i], name[q]) == 0) newScore[i] += score[q]; } } + // printf("Unsorted:\n"); + // for(int i = 0; i < newPos; i++){ + // printf("%d %s\n", newScore[i], newName[i]); + // } + + //Sorting for(int d = 0; d < newPos - 1; d++){ for(int i = 0; i < newPos - 1; i++){ - if(newScore[i] < newScore[i + 1]){ + if(newScore[i] < newScore[i + 1]){ //Score sorting int tmpScore = newScore[i]; newScore[i] = newScore[i + 1]; newScore[i + 1] = tmpScore; @@ -54,10 +63,11 @@ int main(){ strcpy(newName[i + 1], tmpName); } - else if(newScore[i] == newScore[i + 1]){ + else if(newScore[i] == newScore[i + 1]){ //Name sorting int test = 0; for(int q = 0; q < newPos; q++){ if(newName[i][pos] < newName[i + 1][pos]){ + printf("Letters %c %c\n", newName[i][pos], newName[i + 1][pos]); int tmpScore = newScore[i]; newScore[i] = newScore[i + 1]; newScore[i + 1] = tmpScore; @@ -66,17 +76,19 @@ int main(){ strcpy(tmpName, newName[i]); strcpy(newName[i], newName[i + 1]); strcpy(newName[i + 1], tmpName); + printf("If\n"); break; } - else{ - int tmpScore = newScore[i + 1]; - newScore[i + 1] = newScore[i]; - newScore[i] = tmpScore; + else if(newName[i][pos] > newName[i + 1][pos]){ + // int tmpScore = newScore[i + 1]; + // newScore[i + 1] = newScore[i]; + // newScore[i] = tmpScore; - char tmpName[50]; - strcpy(tmpName, newName[i + 1]); - strcpy(newName[i + 1], newName[i]); - strcpy(newName[i], tmpName); + // char tmpName[50]; + // strcpy(tmpName, newName[i + 1]); + // strcpy(newName[i + 1], newName[i]); + // strcpy(newName[i], tmpName); + // printf("Else if\n"); break; } }