From 0bfa0b68c917ba70347b64197af181805e1ad218 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:33:51 +0000 Subject: [PATCH 01/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ^^ --- du6/program.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 5fef565..788e9b0 100644 --- a/du6/program.c +++ b/du6/program.c @@ -1,5 +1,67 @@ #include +#include +#include +#include int main(){ -return 0; + int freePlaces; + char inputs[100][50]; + char* ptr; + int finalPosition; + int count = 0; + char temp[50]; + + for(int i =0; fgets(inputs[i], 50, stdin) != NULL;; i++){ + if(i == 0){ + freePlaces = strtol(inputs[0], &ptr, 10); + if(freePlaces < 0 || !sdigit(freePlaces)){ + printf("Nespravny vstup\n"); + } + } + else if(i == 1 && !salpha(inputs[i][0])){ + printf("Ziadne prihlasky\n"); + return 0; + } + else{ + if(!strcmp(inputs[i], "")){ + break; + } + } + finalPosition = 1; + } + + //Код ниже избавляется от повторных заявок + for(int i = 0; i < finalPosition; i++){ + for(int j = 0; j < finalPosition; j++){ + if(!strcmp(inputs[i], inputs[j])){ + strcpy(inputs[i], inputs[finalPosition]); + memset(inputs[finalPosition], '\0', 50); + } + } + } + + //Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я) + for(int i = 0; i < finalPosition - 1; i++){ + while(inputs[i][count] == inputs[i+1][count]){ + count++; + } + if(inputs[i][count] > inputs[i+1][count]){ + strcpy(temp, inputs[i]); + strcpy(inputs[i], inputs[i+1]); + strcpy(inputs[i+1], temp); + } + } + + puts("Prijati studenti:\n"); + for(int i = 0; i < finalPosition; i++) { + puts ("%s\n", inputs[i]); + if(i == 4) break; + } + puts("Neprijati studenti:\n"); + for(int i = 5; i < finalPosition; i++){ + puts("%s\n", inputs[i]); + } + + free(ptr); + return 0; } From 892284a6db3e2cd98e26e3c3f8631dd8d91bb862 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:36:09 +0000 Subject: [PATCH 02/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ^^ --- du6/program.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/du6/program.c b/du6/program.c index 788e9b0..8b8104f 100644 --- a/du6/program.c +++ b/du6/program.c @@ -11,14 +11,14 @@ int main(){ int count = 0; char temp[50]; - for(int i =0; fgets(inputs[i], 50, stdin) != NULL;; i++){ + for(int i =0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ freePlaces = strtol(inputs[0], &ptr, 10); - if(freePlaces < 0 || !sdigit(freePlaces)){ + if(freePlaces < 0 || !isdigit(freePlaces)){ printf("Nespravny vstup\n"); } } - else if(i == 1 && !salpha(inputs[i][0])){ + else if(i == 1 && !isalpha(inputs[i][0])){ printf("Ziadne prihlasky\n"); return 0; } @@ -54,12 +54,12 @@ int main(){ puts("Prijati studenti:\n"); for(int i = 0; i < finalPosition; i++) { - puts ("%s\n", inputs[i]); + printf ("%s\n", inputs[i]); if(i == 4) break; } puts("Neprijati studenti:\n"); for(int i = 5; i < finalPosition; i++){ - puts("%s\n", inputs[i]); + printf("%s\n", inputs[i]); } free(ptr); From 26e70c29ee87f2ce9696f5f3edafc5584ea7f786 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:37:20 +0000 Subject: [PATCH 03/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 8b8104f..35974fe 100644 --- a/du6/program.c +++ b/du6/program.c @@ -62,6 +62,6 @@ int main(){ printf("%s\n", inputs[i]); } - free(ptr); + //free(ptr); return 0; } From 596eb9dad5d41c40bb131073ce1b29540c6df30b Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:40:05 +0000 Subject: [PATCH 04/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/du6/program.c b/du6/program.c index 35974fe..a95c8a7 100644 --- a/du6/program.c +++ b/du6/program.c @@ -41,7 +41,7 @@ int main(){ } //Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я) - for(int i = 0; i < finalPosition - 1; i++){ + for(int i = 0; i < finalPosition; i++){ while(inputs[i][count] == inputs[i+1][count]){ count++; } @@ -52,13 +52,13 @@ int main(){ } } - puts("Prijati studenti:\n"); - for(int i = 0; i < finalPosition; i++) { + printf("Prijati studenti:\n"); + for(int i = 0; i <= finalPosition; i++) { printf ("%s\n", inputs[i]); if(i == 4) break; } - puts("Neprijati studenti:\n"); - for(int i = 5; i < finalPosition; i++){ + if(5 < finalPosition) printf("Neprijati studenti:\n"); + for(int i = 5; i <= finalPosition; i++){ printf("%s\n", inputs[i]); } From a62df703095579416991cbaabaf3c241952494fa Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:46:38 +0000 Subject: [PATCH 05/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/du6/program.c b/du6/program.c index a95c8a7..99416e9 100644 --- a/du6/program.c +++ b/du6/program.c @@ -53,13 +53,13 @@ int main(){ } printf("Prijati studenti:\n"); - for(int i = 0; i <= finalPosition; i++) { - printf ("%s\n", inputs[i]); - if(i == 4) break; + for(int i = 1; i <= finalPosition+1; i++) { + printf ("%s", inputs[i]); + if(i == 5) break; } - if(5 < finalPosition) printf("Neprijati studenti:\n"); - for(int i = 5; i <= finalPosition; i++){ - printf("%s\n", inputs[i]); + if(6 < finalPosition) printf("Neprijati studenti:\n"); + for(int i = 6; i <= finalPosition; i++){ + printf("%s", inputs[i]); } //free(ptr); From 8ab0829f421bab4a7af45315e205c4ef2337c2bc Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:48:21 +0000 Subject: [PATCH 06/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 99416e9..7354032 100644 --- a/du6/program.c +++ b/du6/program.c @@ -53,7 +53,7 @@ int main(){ } printf("Prijati studenti:\n"); - for(int i = 1; i <= finalPosition+1; i++) { + for(int i = 1; i <= finalPosition; i++) { printf ("%s", inputs[i]); if(i == 5) break; } From 28567fb539495c4a940798daeb2f96d439cd8a7b Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:50:35 +0000 Subject: [PATCH 07/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 7354032..45235fa 100644 --- a/du6/program.c +++ b/du6/program.c @@ -11,11 +11,11 @@ int main(){ int count = 0; char temp[50]; - for(int i =0; fgets(inputs[i], 50, stdin) != NULL; i++){ + for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ freePlaces = strtol(inputs[0], &ptr, 10); if(freePlaces < 0 || !isdigit(freePlaces)){ - printf("Nespravny vstup\n"); + printf("Nespravny vstup %d\n", freePlaces); } } else if(i == 1 && !isalpha(inputs[i][0])){ From 67fc6ff6e5729b828b8c195afc8d4119dbe65c1f Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:52:56 +0000 Subject: [PATCH 08/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 45235fa..2660a36 100644 --- a/du6/program.c +++ b/du6/program.c @@ -13,7 +13,7 @@ int main(){ for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ - freePlaces = strtol(inputs[0], &ptr, 10); + freePlaces = (int) strtol(inputs[0], &ptr, 10); if(freePlaces < 0 || !isdigit(freePlaces)){ printf("Nespravny vstup %d\n", freePlaces); } From a66b6c185a1c9dc6b9114408434fc35456ee809b Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:55:45 +0000 Subject: [PATCH 09/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 2660a36..53a879f 100644 --- a/du6/program.c +++ b/du6/program.c @@ -14,7 +14,7 @@ int main(){ for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ freePlaces = (int) strtol(inputs[0], &ptr, 10); - if(freePlaces < 0 || !isdigit(freePlaces)){ + if(freePlaces < 0 || !isdigit(freePlaces+'0')){ printf("Nespravny vstup %d\n", freePlaces); } } From f2b47c11d18b607a2172cb9bd23742bd04097575 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:00:53 +0000 Subject: [PATCH 10/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 53a879f..70137b6 100644 --- a/du6/program.c +++ b/du6/program.c @@ -14,7 +14,7 @@ int main(){ for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ freePlaces = (int) strtol(inputs[0], &ptr, 10); - if(freePlaces < 0 || !isdigit(freePlaces+'0')){ + if(freePlaces < 0){ printf("Nespravny vstup %d\n", freePlaces); } } From c6023e4c312c24b311d3c78a4678d38bad64827d Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:02:34 +0000 Subject: [PATCH 11/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 70137b6..b74c882 100644 --- a/du6/program.c +++ b/du6/program.c @@ -53,7 +53,7 @@ int main(){ } printf("Prijati studenti:\n"); - for(int i = 1; i <= finalPosition; i++) { + for(int i = 1; i <= finalPosition+1; i++) { printf ("%s", inputs[i]); if(i == 5) break; } From 4303dbfaf8be9a00c08fbf14f22ecb4ab4398931 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:07:16 +0000 Subject: [PATCH 12/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index b74c882..bdeb64a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -54,12 +54,16 @@ int main(){ printf("Prijati studenti:\n"); for(int i = 1; i <= finalPosition+1; i++) { - printf ("%s", inputs[i]); + if(isalpha(inputs[i][0])){ + printf ("%s", inputs[i]); + } if(i == 5) break; } if(6 < finalPosition) printf("Neprijati studenti:\n"); for(int i = 6; i <= finalPosition; i++){ - printf("%s", inputs[i]); + if(isalpha(inputs[i][0])){ + printf("%s", inputs[i]); + } } //free(ptr); From 27b8394a47bbc9cf74f14777b9d0b4dd36be98c2 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:09:26 +0000 Subject: [PATCH 13/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/du6/program.c b/du6/program.c index bdeb64a..fab13df 100644 --- a/du6/program.c +++ b/du6/program.c @@ -53,14 +53,13 @@ int main(){ } printf("Prijati studenti:\n"); - for(int i = 1; i <= finalPosition+1; i++) { + for(int i = 1; i <= freePlaces; i++) { if(isalpha(inputs[i][0])){ printf ("%s", inputs[i]); } - if(i == 5) break; } - if(6 < finalPosition) printf("Neprijati studenti:\n"); - for(int i = 6; i <= finalPosition; i++){ + if(freePlaces < finalPosition) printf("Neprijati studenti:\n"); + for(int i = freePlaces; i <= finalPosition; i++){ if(isalpha(inputs[i][0])){ printf("%s", inputs[i]); } From f63fe07500dc27e46d41a751ffb6df693d9520dd Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:13:47 +0000 Subject: [PATCH 14/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/du6/program.c b/du6/program.c index fab13df..4a08b3b 100644 --- a/du6/program.c +++ b/du6/program.c @@ -31,6 +31,7 @@ int main(){ } //Код ниже избавляется от повторных заявок + for(int i = 0; i < finalPosition; i++){ for(int j = 0; j < finalPosition; j++){ if(!strcmp(inputs[i], inputs[j])){ @@ -41,14 +42,17 @@ int main(){ } //Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я) - for(int i = 0; i < finalPosition; i++){ - while(inputs[i][count] == inputs[i+1][count]){ - count++; - } - if(inputs[i][count] > inputs[i+1][count]){ - strcpy(temp, inputs[i]); - strcpy(inputs[i], inputs[i+1]); - strcpy(inputs[i+1], temp); + int changesMade = 1; + while (changesMade){ + for(int i = 0; i < finalPosition; i++){ + while(inputs[i][count] == inputs[i+1][count]){ + count++; + } + if(inputs[i][count] > inputs[i+1][count]){ + strcpy(temp, inputs[i]); + strcpy(inputs[i], inputs[i+1]); + strcpy(inputs[i+1], temp); + } } } From b50423e94d676914bc2c1f3d5f32d7823d08c219 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:15:55 +0000 Subject: [PATCH 15/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/du6/program.c b/du6/program.c index 4a08b3b..c995c27 100644 --- a/du6/program.c +++ b/du6/program.c @@ -44,11 +44,13 @@ int main(){ //Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я) int changesMade = 1; while (changesMade){ + changesMade = 0; for(int i = 0; i < finalPosition; i++){ while(inputs[i][count] == inputs[i+1][count]){ count++; } if(inputs[i][count] > inputs[i+1][count]){ + changesMade = 1; strcpy(temp, inputs[i]); strcpy(inputs[i], inputs[i+1]); strcpy(inputs[i+1], temp); From f17c4df19edda6ccb72a18e83cdb3d89d4c36ce1 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:18:16 +0000 Subject: [PATCH 16/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 1 + 1 file changed, 1 insertion(+) diff --git a/du6/program.c b/du6/program.c index c995c27..21fa2f8 100644 --- a/du6/program.c +++ b/du6/program.c @@ -55,6 +55,7 @@ int main(){ strcpy(inputs[i], inputs[i+1]); strcpy(inputs[i+1], temp); } + count = 0; } } From 11210eeeba2f4e7c08e719aa103357cb688ad302 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:20:55 +0000 Subject: [PATCH 17/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 21fa2f8..16992ea 100644 --- a/du6/program.c +++ b/du6/program.c @@ -23,7 +23,7 @@ int main(){ return 0; } else{ - if(!strcmp(inputs[i], "")){ + if(!strcmp(inputs[i], "") || inputs[i][0] == '\n'){ break; } } From 145a134edee13386978b49518e9132c59203e59f Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:39:34 +0000 Subject: [PATCH 18/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/du6/program.c b/du6/program.c index 16992ea..98b0eb2 100644 --- a/du6/program.c +++ b/du6/program.c @@ -6,6 +6,9 @@ int main(){ int freePlaces; char inputs[100][50]; + for(int i = 0; i < 100; i++){ + memset(inputs[i], '\0', 50); + } char* ptr; int finalPosition; int count = 0; From 7c88c0f4aacd08119b0a0807ef03cddabdc4f554 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:49:28 +0000 Subject: [PATCH 19/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 54 ++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/du6/program.c b/du6/program.c index 98b0eb2..253360a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -1,14 +1,13 @@ #include -#include #include +#include #include -int main(){ +int main() { int freePlaces; char inputs[100][50]; - for(int i = 0; i < 100; i++){ + for(int i = 0; i < 100; i++) memset(inputs[i], '\0', 50); - } char* ptr; int finalPosition; int count = 0; @@ -16,65 +15,58 @@ int main(){ for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ - freePlaces = (int) strtol(inputs[0], &ptr, 10); - if(freePlaces < 0){ + freePlaces = (int)strtol(inputs[i], &ptr, 10); + if(freePlaces < 0) printf("Nespravny vstup %d\n", freePlaces); - } } else if(i == 1 && !isalpha(inputs[i][0])){ printf("Ziadne prihlasky\n"); return 0; } else{ - if(!strcmp(inputs[i], "") || inputs[i][0] == '\n'){ + if(!strcmp(inputs[i], "") || inputs[i][0] == '\n') break; - } } - finalPosition = 1; + finalPosition = i; } - //Код ниже избавляется от повторных заявок - + //The code below removes repeating applicants for(int i = 0; i < finalPosition; i++){ - for(int j = 0; j < finalPosition; j++){ - if(!strcmp(inputs[i], inputs[j])){ + for(int j = i+1; j < finalPosition; j++){ + if(!strcmp(inputs[i], inputs[j])) { strcpy(inputs[i], inputs[finalPosition]); - memset(inputs[finalPosition], '\0', 50); + memset(inputs[finalPosition--], '\0', 50); } } } - //Этот код отвечает за сортировку заданных имён в списке зачисленных (а-я) + //The code below orders the applicants by name (a-z) int changesMade = 1; - while (changesMade){ + while(changesMade){ changesMade = 0; for(int i = 0; i < finalPosition; i++){ - while(inputs[i][count] == inputs[i+1][count]){ + while(inputs[i][count] == inputs[i + 1][count]) count++; - } - if(inputs[i][count] > inputs[i+1][count]){ + if(inputs[i][count] > inputs[i + 1][count]){ changesMade = 1; strcpy(temp, inputs[i]); - strcpy(inputs[i], inputs[i+1]); - strcpy(inputs[i+1], temp); + strcpy(inputs[i], inputs[i + 1]); + strcpy(inputs[i + 1], temp); } count = 0; } } printf("Prijati studenti:\n"); - for(int i = 1; i <= freePlaces; i++) { - if(isalpha(inputs[i][0])){ - printf ("%s", inputs[i]); - } + for(int i = 1; i <= freePlaces; i++){ + if(isalpha(inputs[i][0])) + printf("%s", inputs[i]); } if(freePlaces < finalPosition) printf("Neprijati studenti:\n"); - for(int i = freePlaces; i <= finalPosition; i++){ - if(isalpha(inputs[i][0])){ + for(int i = freePlaces; i < finalPosition; i++){ + if(isalpha(inputs[i][0])) printf("%s", inputs[i]); - } } - //free(ptr); return 0; -} +} \ No newline at end of file From 62c7779b2acda7316d5e538422dbcd94f1fe7352 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 19:57:49 +0000 Subject: [PATCH 20/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 253360a..b43d1e5 100644 --- a/du6/program.c +++ b/du6/program.c @@ -59,7 +59,7 @@ int main() { printf("Prijati studenti:\n"); for(int i = 1; i <= freePlaces; i++){ - if(isalpha(inputs[i][0])) + if(isalpha(inputs[i][0]) || isalpha(inputs[i][1])) printf("%s", inputs[i]); } if(freePlaces < finalPosition) printf("Neprijati studenti:\n"); From 7c15bb5fb2ebceb42097cbb037f304ee5066dff6 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 10:58:46 +0000 Subject: [PATCH 21/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/du6/program.c b/du6/program.c index b43d1e5..3322f0a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -41,21 +41,7 @@ int main() { } //The code below orders the applicants by name (a-z) - int changesMade = 1; - while(changesMade){ - changesMade = 0; - for(int i = 0; i < finalPosition; i++){ - while(inputs[i][count] == inputs[i + 1][count]) - count++; - if(inputs[i][count] > inputs[i + 1][count]){ - changesMade = 1; - strcpy(temp, inputs[i]); - strcpy(inputs[i], inputs[i + 1]); - strcpy(inputs[i + 1], temp); - } - count = 0; - } - } + qsort(inputs, finalPosition+1, 50*sizeof(char), strcmp); printf("Prijati studenti:\n"); for(int i = 1; i <= freePlaces; i++){ From 9306f733d11dbed9c6fedbff972ecfa911201c8f Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:02:18 +0000 Subject: [PATCH 22/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 3322f0a..1f51774 100644 --- a/du6/program.c +++ b/du6/program.c @@ -45,13 +45,15 @@ int main() { printf("Prijati studenti:\n"); for(int i = 1; i <= freePlaces; i++){ - if(isalpha(inputs[i][0]) || isalpha(inputs[i][1])) + if(inputs[i][0] != '\n' && inputs[i][0] != '\0'){ printf("%s", inputs[i]); + } } if(freePlaces < finalPosition) printf("Neprijati studenti:\n"); for(int i = freePlaces; i < finalPosition; i++){ - if(isalpha(inputs[i][0])) + if(isalpha(inputs[i][0])){ printf("%s", inputs[i]); + } } return 0; From bbd996df3a297eb3a846a12c4b45fb4409d4a692 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:04:18 +0000 Subject: [PATCH 23/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 1f51774..27cf96e 100644 --- a/du6/program.c +++ b/du6/program.c @@ -49,8 +49,8 @@ int main() { printf("%s", inputs[i]); } } - if(freePlaces < finalPosition) printf("Neprijati studenti:\n"); - for(int i = freePlaces; i < finalPosition; i++){ + if(freePlaces+1 < finalPosition) printf("Neprijati studenti:\n"); + for(int i = freePlaces+1; i <= finalPosition; i++){ if(isalpha(inputs[i][0])){ printf("%s", inputs[i]); } From 6c733eae907b3e92dc8a7e391d5e329057359d35 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:05:55 +0000 Subject: [PATCH 24/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 27cf96e..bde1549 100644 --- a/du6/program.c +++ b/du6/program.c @@ -31,8 +31,8 @@ int main() { } //The code below removes repeating applicants - for(int i = 0; i < finalPosition; i++){ - for(int j = i+1; j < finalPosition; j++){ + for(int i = 0; i <= finalPosition; i++){ + for(int j = i+1; j <= finalPosition; j++){ if(!strcmp(inputs[i], inputs[j])) { strcpy(inputs[i], inputs[finalPosition]); memset(inputs[finalPosition--], '\0', 50); From 311b471e321865fa8ff98829f8a9b16223912ebc Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:12:42 +0000 Subject: [PATCH 25/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index bde1549..83765ae 100644 --- a/du6/program.c +++ b/du6/program.c @@ -32,8 +32,8 @@ int main() { //The code below removes repeating applicants for(int i = 0; i <= finalPosition; i++){ - for(int j = i+1; j <= finalPosition; j++){ - if(!strcmp(inputs[i], inputs[j])) { + for(int j = 0; j <= finalPosition; j++){ + if(!strcmp(inputs[i], inputs[j]) && i != j) { strcpy(inputs[i], inputs[finalPosition]); memset(inputs[finalPosition--], '\0', 50); } From b8f5fd589c2069c80395df3926ec7a63dae90a65 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:14:17 +0000 Subject: [PATCH 26/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 83765ae..323c497 100644 --- a/du6/program.c +++ b/du6/program.c @@ -16,8 +16,10 @@ int main() { for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ freePlaces = (int)strtol(inputs[i], &ptr, 10); - if(freePlaces < 0) - printf("Nespravny vstup %d\n", freePlaces); + if(freePlaces < 0){ + printf("Nespravny vstup\n", freePlaces); + return 0; + } } else if(i == 1 && !isalpha(inputs[i][0])){ printf("Ziadne prihlasky\n"); From 44532ee1e23703904acc9d577dbdc57aa7aba762 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:21:08 +0000 Subject: [PATCH 27/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/du6/program.c b/du6/program.c index 323c497..48a62b6 100644 --- a/du6/program.c +++ b/du6/program.c @@ -11,13 +11,19 @@ int main() { char* ptr; int finalPosition; int count = 0; - char temp[50]; for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ + inputs[i][strlen(inputs[i])-1] = '\0' + for(int j = 0; j < strlen(inputs[i]); j++){ + if(!isdigit(inputs[i][j])){ + printf("Nespravny vstup\n"); + return 0; + } + } freePlaces = (int)strtol(inputs[i], &ptr, 10); if(freePlaces < 0){ - printf("Nespravny vstup\n", freePlaces); + printf("Nespravny vstup\n"); return 0; } } From 611e34ea26698abd8d829a8f11d31794b388817e Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:22:02 +0000 Subject: [PATCH 28/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 48a62b6..097d66a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -14,7 +14,7 @@ int main() { for(int i = 0; fgets(inputs[i], 50, stdin) != NULL; i++){ if(i == 0){ - inputs[i][strlen(inputs[i])-1] = '\0' + inputs[i][strlen(inputs[i])-1] = '\0'; for(int j = 0; j < strlen(inputs[i]); j++){ if(!isdigit(inputs[i][j])){ printf("Nespravny vstup\n"); From a9aa051a194842c9ad8a2b1c640058d481afc5e9 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 16 Apr 2021 11:23:40 +0000 Subject: [PATCH 29/29] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/du6/program.c b/du6/program.c index 097d66a..88d266a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -22,7 +22,7 @@ int main() { } } freePlaces = (int)strtol(inputs[i], &ptr, 10); - if(freePlaces < 0){ + if(freePlaces <= 0){ printf("Nespravny vstup\n"); return 0; }