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