test
This commit is contained in:
parent
301029a4cd
commit
a4df11eb59
@ -35,37 +35,38 @@ int main() {
|
||||
|
||||
if (student_count == 0) {
|
||||
total_votes = vote_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
int existing_student_index = -1;
|
||||
for (int i = 0; i < student_count; i++) {
|
||||
if (strcmp(students[i].name, name) == 0) {
|
||||
existing_student_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (existing_student_index != -1) {
|
||||
students[existing_student_index].vote_count += vote_count;
|
||||
} else {
|
||||
if (student_count >= students_capacity) {
|
||||
students_capacity = (students_capacity + 1) * 2;
|
||||
student_t *new_students = realloc(students, students_capacity * sizeof(student_t));
|
||||
if (new_students == NULL) {
|
||||
fprintf(stderr, "Error: Memory reallocation failed\n");
|
||||
return 1;
|
||||
int existing_student_index = -1;
|
||||
for (int i = 0; i < student_count; i++) {
|
||||
if (strcmp(students[i].name, name) == 0) {
|
||||
existing_student_index = i;
|
||||
break;
|
||||
}
|
||||
students = new_students;
|
||||
}
|
||||
|
||||
students[student_count].name = strdup(name);
|
||||
students[student_count].vote_count = vote_count;
|
||||
student_count++;
|
||||
if (existing_student_index != -1) {
|
||||
students[existing_student_index].vote_count += vote_count;
|
||||
} else {
|
||||
if (student_count >= students_capacity) {
|
||||
students_capacity = (students_capacity + 1) * 2;
|
||||
student_t *new_students = realloc(students, students_capacity * sizeof(student_t));
|
||||
if (new_students == NULL) {
|
||||
fprintf(stderr, "Error: Memory reallocation failed\n");
|
||||
return 1;
|
||||
}
|
||||
students = new_students;
|
||||
}
|
||||
|
||||
students[student_count].name = strdup(name);
|
||||
students[student_count].vote_count = vote_count;
|
||||
student_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (student_count == 1) {
|
||||
if (student_count == 0) {
|
||||
printf("Žiadni študenti.\n");
|
||||
} else if (student_count == 1) {
|
||||
printf("Vysledky:\n");
|
||||
printf("%d %s\n", total_votes, students[0].name);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user