#include #include int main() { char listM[20][20]; int listH[50]; int studentCount = 0; int aHlasy; char aMeno[30]; while (scanf("%d", &aHlasy) == 1) { getchar(); fgets(aMeno, sizeof(aMeno), stdin); aMeno[strcspn(aMeno, "\n")] = 0; int i; for (i = 0; i < studentCount; i++) { if (strcmp(listM[i], aMeno) == 0) { listH[i] += aHlasy; break; } } if (i == studentCount) { strncpy(listM[studentCount], aMeno, sizeof(listM[studentCount]) - 1); listM[studentCount][sizeof(listM[studentCount]) - 1] = '\0'; // zabezpečenie ukončenia reťazca listH[studentCount] = aHlasy; studentCount++; } } if (studentCount == 0) { printf("Chyba: Ziadne hlasy neboli nacitane\n"); return 1; } for (int i = 0; i < studentCount; i++) { for (int j = 0; j < studentCount - 1; j++) { if (listH[j] < listH[j + 1]) { int docasneHlasy = listH[j]; listH[j] = listH[j + 1]; listH[j + 1] = docasneHlasy; char docasneMeno[20]; strncpy(docasneMeno, listM[j], sizeof(docasneMeno) - 1); docasneMeno[sizeof(docasneMeno) - 1] = '\0'; // zabezpečenie ukončenia reťazca strncpy(listM[j], listM[j + 1], sizeof(listM[j]) - 1); listM[j][sizeof(listM[j]) - 1] = '\0'; // zabezpečenie ukončenia reťazca strncpy(listM[j + 1], docasneMeno, sizeof(listM[j + 1]) - 1); listM[j + 1][sizeof(listM[j + 1]) - 1] = '\0'; // zabezpečenie ukončenia reťazca } else if (listH[j] == listH[j + 1] && strcmp(listM[j], listM[j + 1]) > 0) { char docasneMeno[20]; strncpy(docasneMeno, listM[j], sizeof(docasneMeno) - 1); docasneMeno[sizeof(docasneMeno) - 1] = '\0'; // zabezpečenie ukončenia reťazca strncpy(listM[j], listM[j + 1], sizeof(listM[j]) - 1); listM[j][sizeof(listM[j]) - 1] = '\0'; // zabezpečenie ukončenia reťazca strncpy(listM[j + 1], docasneMeno, sizeof(listM[j + 1]) - 1); listM[j + 1][sizeof(listM[j + 1]) - 1] = '\0'; // zabezpečenie ukončenia reťazca } } } printf("Vysledky:\n"); for (int i = 0; i < studentCount; i++) { printf("%d %s\n", listH[i], listM[i]); } return 0; }