diff --git a/program b/program new file mode 100644 index 0000000..26c9fc7 Binary files /dev/null and b/program differ diff --git a/program.c b/program.c new file mode 100644 index 0000000..c5529a7 --- /dev/null +++ b/program.c @@ -0,0 +1,117 @@ +#include +#include +#include +struct clovek +{ + int holos; + char name[60]; +}; + +void printAll(struct clovek clovek[50],int number_clovek){ + printf("Vysledky:\n"); + for (size_t i = 0; i < number_clovek; i++) + { + printf("%d", clovek[i].holos); + printf("%s", clovek[i].name); + } +} +void readDellSame(bool je_toiste, bool je_dobre, int* number_clovek, struct clovek clovek[50]){ + for (size_t i = 0; i >=0; i++) + { + char step_name[60]; + int step_holos =0; + int r = scanf("%d", &step_holos); + if (r == -1) + { + break; + } + if (step_holos == 0) + { + je_dobre = true; + } + + fgets(step_name, 60 , stdin);//prečíta riadok z terminálu + for (size_t j = 0; j <*number_clovek; j++) + { + if(strcmp (clovek[j].name, step_name)==0 && je_dobre == false ){//porovnáva struny + clovek[j].holos += step_holos; + je_toiste = true; + i--; + } + } + if ((je_toiste == false|| *number_clovek == 0) && je_dobre == false) + { + clovek[i].holos = step_holos; + strcpy(clovek[i].name, step_name);//strcpy-koreluje časti pamäte + *number_clovek = *number_clovek +1 ; + } + je_toiste = false; + } +} + +void sortMas(int number_clovek, struct clovek clovek[50]){ + for (size_t i = 0; i clovek[j].name[1]){ + int tmp = clovek[i].holos; + char tmp_name[60]; + strcpy(tmp_name, clovek[i].name); + + clovek[i].holos = clovek[j].holos; + strcpy(clovek[i].name, clovek[j].name); + + clovek[j].holos = tmp; + strcpy(clovek[j].name, tmp_name); + } + if(clovek[i].name[1] == clovek[j].name[1]) + { + if(clovek[i].name[2] > clovek[j].name[2]){ + int tmp = clovek[i].holos; + char tmp_name[60]; + strcpy(tmp_name, clovek[i].name); + + clovek[i].holos = clovek[j].holos; + strcpy(clovek[i].name, clovek[j].name); + + clovek[j].holos = tmp; + strcpy(clovek[j].name, tmp_name); + } + } + } + } + } +} +int main(){ + struct clovek clovek[50]; + int number_clovek = 0; + bool je_toiste = false; + bool je_dobre = false; + readDellSame(je_toiste, je_dobre, &number_clovek,clovek); + for (size_t i = 0; i < number_clovek-1; i++) + { + for (size_t j = 0; j < number_clovek - i-1; j++) + { + if (clovek[j].holos < clovek[j+1].holos) + { + int tmp = clovek[j+1].holos; + char tmp_name[60]; + strcpy(tmp_name, clovek[j+1].name); + + clovek[j+1].holos = clovek[j].holos; + strcpy(clovek[j+1].name, clovek[j].name); + + clovek[j].holos = tmp; + strcpy(clovek[j].name, tmp_name); + } + + } + + } + sortMas(number_clovek, clovek); + printAll(clovek, number_clovek); + return 0; +} \ No newline at end of file