From 0260a0c70a0c1a2bdd31a37ac3652f36c58a3774 Mon Sep 17 00:00:00 2001 From: st529yr Date: Thu, 21 Mar 2024 23:45:41 +0100 Subject: [PATCH] funguje --- cv5/program.c | 54 --------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 cv5/program.c diff --git a/cv5/program.c b/cv5/program.c deleted file mode 100644 index b406480..0000000 --- a/cv5/program.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#define MAX_STUDENTS 100 -#define MAX_NAME_LENGTH 100 - -// Štruktúra pre reprezentáciu študenta -struct Student { - char name[MAX_NAME_LENGTH]; - int votes; -}; - -// Porovnávacia funkcia pre qsort -int compare_students(const void* a, const void* b) { - const struct Student* studentA = (const struct Student*)a; - const struct Student* studentB = (const struct Student*)b; - - // Porovnanie podľa počtu hlasov - if (studentA->votes != studentB->votes) { - return studentB->votes - studentA->votes; // Zotriedenie zostupne podľa počtu hlasov - } else { - // Ak majú rovnaký počet hlasov, zotriedenie podľa mena - return strcmp(studentA->name, studentB->name); - } -} - -int main() { - // Databáza študentov s preddefinovanými hodnotami - struct Student students[MAX_STUDENTS] = { - {"Terian Dis", 10}, // Terian Dis má 10 hlasov - {"Bardos Mrtakrys", 2}, - {"Rita Umhi", 1}, - {"Prylenn Alak", 1}, - {"Lak'hi Elavorg", 9}, // Lak'hi Elavorg má menej ako 10 hlasov - {"Prylenn Alak", 3}, - {"Prylenn Alak", 3}, - {"Prylenn Alak", 3}, - {"Rita Umhi", 1} - }; - int num_students = 9; // Počet študentov v databáze - - // Zoradenie študentov podľa počtu hlasov a mena - qsort(students, num_students, sizeof(struct Student), compare_students); - - // Výpis zoradeného zoznamu študentov - printf("Výsledky:\n"); - for (int i = 0; i < num_students; i++) { - printf("%d %s\n", students[i].votes, students[i].name); - } - - return 0; -} -