diff --git a/du2/program.c b/du2/program.c index 7c61a37..4cec9d2 100644 --- a/du2/program.c +++ b/du2/program.c @@ -5,8 +5,10 @@ #define SIZE 100 struct student { + char meno[SIZE]; int hlasy; + }; int najdi_studenta(struct student* studenti, int pocet, const char* meno) { @@ -23,18 +25,16 @@ int porovnaj(const void* p1, const void* p2) { struct student* s1 = (struct student*)p1; struct student* s2 = (struct student*)p2; - if (s2->hlasy > s1->hlasy) return -1; if (s2->hlasy < s1->hlasy) return 1; - return strcmp(s1->meno, s2->meno); + } int main() { struct student databaza[SIZE]; memset(databaza, 0, SIZE * sizeof(struct student)); - int pocet = 0; char riadok[SIZE]; @@ -66,7 +66,6 @@ int main() { char meno[SIZE]; memset(meno, 0, SIZE); - int velkost_mena = (int)strlen(zaciatok_mena); if (zaciatok_mena[velkost_mena - 1] == '\n') { @@ -83,29 +82,28 @@ int main() { int index = najdi_studenta(databaza, pocet, meno); if (index < 0) { - if (pocet >= SIZE) { break; } memcpy(databaza[pocet].meno, meno, velkost_mena); databaza[pocet].meno[velkost_mena] = '\0'; - databaza[pocet].hlasy = hodnota; pocet++; } else { - databaza[index].hlasy += hodnota; - } } qsort(databaza, pocet, sizeof(struct student), porovnaj); + printf("Vysledky:\n"); + for (int i = 0; i < pocet; i++) { - printf("%s %d\n", databaza[i].meno, databaza[i].hlasy); + printf("%d %s\n", databaza[i].hlasy, databaza[i].meno); } return 0; } +