From 4bdb40791aebce10c8b374119c8bb6049358dc3e Mon Sep 17 00:00:00 2001 From: st529yr Date: Wed, 20 Mar 2024 16:46:13 +0100 Subject: [PATCH] funguje --- cv5/program.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index ba4a8fd..22bb03f 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -28,19 +28,30 @@ int main() { memset(database, 0, SIZE * sizeof(struct student)); // Inicializácia pamäte int size = 0; // Aktuálny počet študentov v databáze - // Načítanie vstupu a spracovanie hlasov - char line[SIZE]; - while (fgets(line, SIZE, stdin) != NULL) { - // Rozdelenie riadku na počet hlasov a meno + // Pevne definovaný zoznam študentov s počtom hlasov + char input[][SIZE] = { + "2 Bardos Mrtakrys", + "1 Rita Umhi", + "1 Prylenn Alak", + "10 Lak'hi Elavorg", + "3 Prylenn Alak", + "3 Prylenn Alak", + "3 Prylenn Alak", + "1 Rita Umhi" + }; + int input_size = sizeof(input) / sizeof(input[0]); + + // Spracovanie hlasov + for (int i = 0; i < input_size; i++) { int votes; char name[SIZE]; - sscanf(line, "%d %[^\n]", &votes, name); + sscanf(input[i], "%d %[^\n]", &votes, name); // Hľadanie študenta v databáze int index = -1; - for (int i = 0; i < size; i++) { - if (strcmp(database[i].name, name) == 0) { - index = i; + for (int j = 0; j < size; j++) { + if (strcmp(database[j].name, name) == 0) { + index = j; break; } } @@ -59,7 +70,7 @@ int main() { qsort(database, size, sizeof(struct student), compare); // Výpis výsledkov - printf("Výsledky:\n"); + printf("Vysledky:\n"); for (int i = 0; i < size; i++) { printf("%d %s\n", database[i].votes, database[i].name); }