#include #include #define MAX_NAMELEN 50 #define MAX_STUDENTS 100 typedef struct { char name[MAX_NAMELEN]; int votes; } Student; int main() { Student studenty[MAX_STUDENTS]; char name[MAX_NAMELEN]; char line[255]; int znayd = 0; int golosa=0; int kilkstudentiv = 0; while (fgets(line, sizeof(line), stdin)) { if (sscanf(line, "%d %[^\n]", &golosa, name) != 2 || golosa <= 0) { if (kilkstudentiv == 0) { printf("Chyba: Neplatný vstup.\n"); return 1; } break; } znayd=0; for (int i = 0; i < kilkstudentiv; i++) { if (strcmp(studenty[i].name, name) == 0) { studenty[i].votes += golosa; znayd = 1; break; } } if (znayd == 0) { strcpy(studenty[kilkstudentiv].name, name); studenty[kilkstudentiv].votes = golosa; kilkstudentiv++; } } if (kilkstudentiv == 0) { printf("Chyba: Neplatný vstup.\n"); return 1; } for (int i = 0; i < kilkstudentiv - 1; i++) { for (int j = i + 1; j < kilkstudentiv; j++) { if (studenty[i].votes < studenty[j].votes || (studenty[i].votes == studenty[j].votes && strcmp(studenty[i].name, studenty[j].name) > 0)) { Student change = studenty[i]; studenty[i] = studenty[j]; studenty[j] = change; } } } printf("Vysledky:\n"); for (int i = 0; i < kilkstudentiv; i++) { printf("%d %s\n", studenty[i].votes, studenty[i].name); } return 0; }