Загрузил(а) файлы в ''
This commit is contained in:
parent
e327254de2
commit
006669769d
117
program.c
Normal file
117
program.c
Normal file
@ -0,0 +1,117 @@
|
||||
#include<stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
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 <number_clovek; i++)
|
||||
{
|
||||
for (size_t j = i; j < number_clovek; j++)
|
||||
{
|
||||
if (clovek[i].holos == clovek[j].holos)
|
||||
{
|
||||
if(clovek[i].name[1] > 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user