This commit is contained in:
Rudolf Zambory 2025-03-21 12:15:55 +01:00
parent 6c5785bfe3
commit 9226e6f4a6
2 changed files with 64 additions and 0 deletions

BIN
du4/program Executable file

Binary file not shown.

64
du4/program.c Normal file
View File

@ -0,0 +1,64 @@
#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;
}