From b1b7feb049deefd9e497daa2c07a65230fc9f76d Mon Sep 17 00:00:00 2001 From: Artem Horbunov Date: Wed, 8 Apr 2020 14:52:48 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu6/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/du6/program.c b/du6/program.c index e69de29..4a42b3a 100644 --- a/du6/program.c +++ b/du6/program.c @@ -0,0 +1,84 @@ +#include +#include + +int main(){ + int tmpCh; + tmpCh = getc(stdin); + if(tmpCh < '1' || tmpCh > '9'){ + puts("Nespravny vstup"); + return 0; + } + ungetc(tmpCh, stdin); + + int lines; + scanf("%d", &lines); + scanf("%*c"); + + int realLines = 0; + char names[200][200]; + for(int i = 0; i < 200; i++){ + tmpCh = getc(stdin); + if(tmpCh == '\n' && i == 0){ + puts("Ziadne prihlasky"); + return 0; + } + else if(tmpCh == '\n') break; + ungetc(tmpCh, stdin); + scanf("%s", names[i]); + realLines++; + tmpCh = getc(stdin); + if(tmpCh == EOF) break; + } + + char newNames[200][200]; + int newLines = 0; + + for(int i = 0; i < realLines; i++){ + int check = 1; + for(int q = 0; q < newLines; q++){ + if(strcmp(names[i], newNames[q]) == 0){ + check = 0; + break; + } + } + if(check == 1){ + strcpy(newNames[newLines], names[i]); + newLines++; + } + } + + for(int d = 0; d < newLines - 1; d++){ + for(int i = 0; i < newLines - 1; i++){ + int test = 0; + for(int q = 0; q < newLines; q++){ + if(newNames[i][q] > newNames[i + 1][q]){ + char tmpName[50]; + strcpy(tmpName, newNames[i]); + strcpy(newNames[i], newNames[i + 1]); + strcpy(newNames[i + 1], tmpName); + break; + } + else if(newNames[i][q] < newNames[i + 1][q]){ + break; + } + } + } + } + + if(newLines <= lines){ + puts("Prijati studenti:"); + for(int i = 0; i < newLines; i++){ + printf("%s\n", newNames[i]); + } + } + else{ + puts("Prijati studenti:"); + for(int i = 0; i < lines; i++){ + printf("%s\n", newNames[i]); + } + puts("Neprijati studenti:"); + for(int i = lines; i < newLines; i++){ + printf("%s\n", newNames[i]); + } + } +} \ No newline at end of file