70 lines
2.3 KiB
C
70 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
char listM[50][50];
|
|
int listH[1000];
|
|
int studentCount = 0;
|
|
int aHlasy;
|
|
char aMeno[50];
|
|
|
|
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'; 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[50];
|
|
strncpy(docasneMeno, listM[j], sizeof(docasneMeno) - 1);
|
|
docasneMeno[sizeof(docasneMeno) - 1] = '\0';
|
|
strncpy(listM[j], listM[j + 1], sizeof(listM[j]) - 1);
|
|
listM[j][sizeof(listM[j]) - 1] = '\0';
|
|
strncpy(listM[j + 1], docasneMeno, sizeof(listM[j + 1]) - 1);
|
|
listM[j + 1][sizeof(listM[j + 1]) - 1] = '\0';
|
|
}
|
|
else if (listH[j] == listH[j + 1] && strcmp(listM[j], listM[j + 1]) > 0) {
|
|
char docasneMeno[50];
|
|
strncpy(docasneMeno, listM[j], sizeof(docasneMeno) - 1);
|
|
docasneMeno[sizeof(docasneMeno) - 1] = '\0';
|
|
strncpy(listM[j], listM[j + 1], sizeof(listM[j]) - 1);
|
|
listM[j][sizeof(listM[j]) - 1] = '\0';
|
|
strncpy(listM[j + 1], docasneMeno, sizeof(listM[j + 1]) - 1);
|
|
listM[j + 1][sizeof(listM[j + 1]) - 1] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("Vysledky:\n");
|
|
for (int i = 0; i < studentCount; i++) {
|
|
printf("%d %s\n", listH[i], listM[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|