From b196939627e26c4914bec5c3a57c1209dcd8eeee Mon Sep 17 00:00:00 2001 From: Artem Horbunov Date: Tue, 7 Apr 2020 11:36:47 +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 | 87 +-------------------------------------------------- 1 file changed, 1 insertion(+), 86 deletions(-) diff --git a/du5/program.c b/du5/program.c index 4ab963f..cf34882 100644 --- a/du5/program.c +++ b/du5/program.c @@ -1,90 +1,5 @@ #include -#include int main(){ - char name[50][50]; - int score[50]; - int pos = 0; - while(1){ - scanf("%[^0-9] %d", name[pos], &score[pos]); - scanf("%*c"); - pos++; - int tmpCh = getc(stdin); - if(tmpCh == '\n') break; - ungetc(tmpCh, stdin); - } - - char newName[50][50]; - int newScore[50]; - int newPos = 0; - - for(int i = 0; i < pos; i++){ - int check = 0; - for(int q = 0; q < newPos; q++){ - if(q != i){ - if(strcmp(name[i], newName[q]) == 0){ - check = 1; - break; - } - } - } - if(check == 0){ - strcpy(newName[newPos], name[i]); - newScore[newPos] = 0; - newPos++; - } - } - - 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]; - } - } - - for(int i = 0; i < newPos - 1; i++){ - if(newScore[i] < newScore[i + 1]){ - int tmpScore = newScore[i]; - newScore[i] = newScore[i + 1]; - newScore[i + 1] = tmpScore; - - char tmpName[50]; - strcpy(tmpName, newName[i]); - strcpy(newName[i], newName[i + 1]); - strcpy(newName[i + 1], tmpName); - - i = 0; - } - else if(newScore[i] == newScore[i + 1]){ - int test = 0; - for(int q = 0; q < newPos; q++){ - if(newName[i][pos] < newName[i + 1][pos]){ - int tmpScore = newScore[i]; - newScore[i] = newScore[i + 1]; - newScore[i + 1] = tmpScore; - - char tmpName[50]; - strcpy(tmpName, newName[i]); - strcpy(newName[i], newName[i + 1]); - strcpy(newName[i + 1], tmpName); - break; - } - else{ - 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); - break; - } - } - } - } - - printf("\n"); - for(int i = 0; i < newPos; i++){ - printf("%d %s\n", newScore[i], newName[i]); - } +printf("3\n"); } \ No newline at end of file