From 0bfa0b68c917ba70347b64197af181805e1ad218 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 15 Apr 2021 18:33:51 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=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; }