diff --git a/du4/program b/du4/program new file mode 100755 index 0000000..d81169d Binary files /dev/null and b/du4/program differ diff --git a/du4/program.c b/du4/program.c new file mode 100644 index 0000000..7687467 --- /dev/null +++ b/du4/program.c @@ -0,0 +1,64 @@ +#include +#include + +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; +}