From c8aacba01c757c95d45139fe016b5a10f271004c Mon Sep 17 00:00:00 2001 From: Weber Date: Wed, 24 Apr 2024 10:03:41 +0000 Subject: [PATCH] test --- cv10/program.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/cv10/program.c b/cv10/program.c index e69de29..0f06b3b 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -0,0 +1,64 @@ +#include +#include +#include + +#define MAX_STUDENTS 20 + +int main() { + int maxStudents; + printf("Zadajte maximálny počet študentov na prijatie: "); + scanf("%d", &maxStudents); + + if (maxStudents <= 0) { + printf("Nespravny vstup\n"); + return 1; + } + + char names[MAX_STUDENTS][50]; + int numStudents = 0; + char line[100]; + + fgets(line, sizeof(line), stdin); + + while (fgets(line, sizeof(line), stdin) != NULL && line[0] != '\n') { + line[strcspn(line, "\n")] = '\0'; + strcpy(names[numStudents], line); + numStudents++; + + if (numStudents >= MAX_STUDENTS) { + printf("Príliš veľa študentov. Zvážte navýšenie MAX_STUDENTS.\n"); + return 1; + } + } + + if (numStudents == 0) { + printf("Ziadne prihlášky\n"); + return 1; + } + + for (int i = 0; i < numStudents; i++) { + for (int j = i + 1; j < numStudents; j++) { + if (strcmp(names[i], names[j]) == 0) { + memmove(&names[j], &names[j + 1], (numStudents - j - 1) * sizeof(names[0])); + numStudents--; + j--; + } + } + } + + qsort(names, numStudents, sizeof(names[0]), strcmp); + + printf("\nPrijati studenti:\n"); + for (int i = 0; i < maxStudents && i < numStudents; i++) { + printf("%s\n", names[i]); + } + + if (numStudents > maxStudents) { + printf("\nNeprijati studenti:\n"); + for (int i = maxStudents; i < numStudents; i++) { + printf("%s\n", names[i]); + } + } + + return 0; +} \ No newline at end of file