refresh
This commit is contained in:
parent
ad8f78db53
commit
1b0f27ad83
@ -14,9 +14,9 @@ int compare_students(const void *a, const void *b) {
|
||||
const Student *studentB = (const Student *)b;
|
||||
|
||||
if (studentA->votes != studentB->votes) {
|
||||
return studentB->votes - studentA->votes; // Сортировка по убыванию голосов
|
||||
return studentB->votes - studentA->votes;
|
||||
} else {
|
||||
return strcmp(studentA->name, studentB->name); // Лексикографическая сортировка по имени
|
||||
return strcmp(studentA->name, studentB->name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,10 +30,9 @@ int main() {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
|
||||
if (sscanf(line, "%d %[^\n]", &votes, name) != 2) {
|
||||
break; // Прерываем чтение при неверном формате
|
||||
}
|
||||
break;
|
||||
|
||||
// Поиск студента в массиве
|
||||
|
||||
int found = 0;
|
||||
for (int i = 0; i < student_count; i++) {
|
||||
if (strcmp(students[i].name, name) == 0) {
|
||||
@ -43,12 +42,8 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Если студент не найден, добавляем нового
|
||||
if (!found) {
|
||||
strcpy(students[student_count].name, name);
|
||||
students[student_count].votes = votes;
|
||||
student_count++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (student_count == 0) {
|
||||
@ -56,10 +51,10 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Сортировка студентов
|
||||
|
||||
qsort(students, student_count, sizeof(Student), compare_students);
|
||||
|
||||
// Вывод результатов
|
||||
|
||||
printf("Vysledky:\n");
|
||||
for (int i = 0; i < student_count; i++) {
|
||||
printf("%d %s\n", students[i].votes, students[i].name);
|
||||
|
Loading…
Reference in New Issue
Block a user