From 781c4bbc3923bffe971d5fe73ee071ab681baeaf Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Mon, 15 Apr 2024 21:59:02 +0200 Subject: [PATCH] 1111111111 --- du10/program.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 du10/program.c diff --git a/du10/program.c b/du10/program.c new file mode 100644 index 0000000..01d53be --- /dev/null +++ b/du10/program.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#define SIZE 100 + +int compare(const void* arg1, const void* arg2) { + char* s1 = *((char**)arg1); + char* s2 = *((char**)arg2); + return strcmp(s1, s2); +} + +int main() { + char* pole_smernikov[SIZE]; + memset(pole_smernikov, 0, SIZE * sizeof(char*)); + int pocet_mien_v_poli = 0; + + char line[SIZE]; + while (fgets(line, SIZE, stdin) != NULL) { + int pocet_znakov = strlen(line); + if (pocet_znakov == 1 && line[0] == '\n') // Skončiť na prázdnom riadku + break; + + // Kontrola duplicít + int found = 0; + for (int i = 0; i < pocet_mien_v_poli; i++) { + if (memcmp(pole_smernikov[i], line, pocet_znakov) == 0) { + found = 1; + break; + } + } + if (!found) { + pole_smernikov[pocet_mien_v_poli] = malloc(pocet_znakov); + memcpy(pole_smernikov[pocet_mien_v_poli], line, pocet_znakov); + pocet_mien_v_poli += 1; + } + } + + // Triedenie + qsort(pole_smernikov, pocet_mien_v_poli, sizeof(char*), compare); + + // Výpis prijatých a neprijatých študentov + int max_students; + scanf("%d", &max_students); + + printf("Prijati studenti:\n"); + for (int i = 0; i < max_students && i < pocet_mien_v_poli; i++) { + printf("%s", pole_smernikov[i]); + } + + printf("Neprijati studenti:\n"); + for (int i = max_students; i < pocet_mien_v_poli; i++) { + printf("%s", pole_smernikov[i]); + } + + // Uvoľnenie pamäte + for (int i = 0; i < pocet_mien_v_poli; i++) { + free(pole_smernikov[i]); + } + + return 0; +}