65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
char listM[20][20];
|
|
int listH[50];
|
|
int studentCount = 0;
|
|
int aHlasy;
|
|
char aMeno[30];
|
|
char medzera;
|
|
int i;
|
|
|
|
while (scanf("%d", &aHlasy) == 1) {
|
|
scanf("%c", &medzera);
|
|
fgets(aMeno, 30, stdin);
|
|
aMeno[strlen(aMeno)-1] = '\0';
|
|
|
|
for (i = 0; i < studentCount; i++) {
|
|
if (strcmp(listM[i], aMeno) == 0) {
|
|
listH[i] += aHlasy;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (i == studentCount) {
|
|
strcpy(listM[studentCount], aMeno);
|
|
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];
|
|
strcpy(docasneMeno, listM[j]);
|
|
strcpy(listM[j], listM[j + 1]);
|
|
strcpy(listM[j + 1], docasneMeno);
|
|
}
|
|
else if (listH[j] == listH[j + 1] && strcmp(listM[j], listM[j + 1]) > 0) {
|
|
char docasneMeno[20];
|
|
strcpy(docasneMeno, listM[j]);
|
|
strcpy(listM[j], listM[j + 1]);
|
|
strcpy(listM[j + 1], docasneMeno);
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("Vysledky:\n");
|
|
for (int i = 0; i < studentCount; i++) {
|
|
printf("%d %s\n", listH[i], listM[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|