skuska
This commit is contained in:
parent
5ad31b7526
commit
c057acd40a
@ -41,22 +41,27 @@ int main() {
|
|||||||
students = new_students;
|
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].name = strdup(name);
|
||||||
students[student_count].vote_count = vote_count;
|
students[student_count].vote_count = vote_count;
|
||||||
student_count++;
|
student_count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qsort(students, student_count, sizeof(student_t), compare_students);
|
qsort(students, student_count, sizeof(student_t), compare_students);
|
||||||
|
|
||||||
printf("Vysledky:\n");
|
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++) {
|
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[i].name);
|
||||||
}
|
}
|
||||||
free(students);
|
free(students);
|
||||||
|
Loading…
Reference in New Issue
Block a user