This commit is contained in:
Weber 2024-03-21 21:20:11 +00:00
parent 5ad31b7526
commit c057acd40a

View File

@ -41,22 +41,27 @@ int main() {
students = new_students;
}
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].name, name) == 0) {
students[i].vote_count += vote_count; // Sčítaj nové hlasy k existujúcemu počtu hlasov študenta
found = 1;
break;
}
}
if (!found) {
students[student_count].name = strdup(name);
students[student_count].vote_count = vote_count;
student_count++;
}
}
qsort(students, student_count, sizeof(student_t), compare_students);
printf("Vysledky:\n");
printf("%d %s\n", students[0].vote_count, students[0].name);
for (int i = 1; i < student_count; i++) {
if (strcmp(students[i].name, students[i - 1].name) != 0) {
printf("%d %s\n", students[i].vote_count, students[i].name);
}
}
for (int i = 0; i < student_count; i++) {
printf("%d %s\n", students[i].vote_count, students[i].name);
free(students[i].name);
}
free(students);