#include #include #include #define MAX_LEN 256 #define MAX_NAME_LEN 100 typedef struct { char name[MAX_NAME_LEN]; int votes; } Student; int compare_students(const void *a, const void *b) { Student *student_a = (Student *)a; Student *student_b = (Student *)b; if (student_b->votes != student_a->votes) { return student_b->votes - student_a->votes; } return strcmp(student_a->name, student_b->name); } int main() { Student students[MAX_LEN]; int student_count = 0; char line[MAX_LEN]; while (fgets(line, MAX_LEN, stdin)) { int votes; char name[MAX_NAME_LEN]; if (sscanf(line, "%d %[^\n]", &votes, name) != 2) { if (student_count == 0) { printf("CHYBA\n"); return 0; } break; } int found = 0; for (int i = 0; i < student_count; i++) { if (strcmp(students[i].name, name) == 0) { students[i].votes += votes; found = 1; break; } } if (!found) { if (student_count < MAX_LEN) { strcpy(students[student_count].name, name); students[student_count].votes = votes; student_count++; } else { printf("CHYBA\n"); return 0; } } } qsort(students, student_count, sizeof(Student), compare_students); printf("Результаты:\n"); for (int i = 0; i < student_count; i++) { printf("%d %s\n", students[i].votes, students[i].name); } return 0; }