45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE 100
|
|
|
|
struct student {
|
|
char name[SIZE];
|
|
int votes;
|
|
};
|
|
|
|
int main() {
|
|
|
|
//premenne
|
|
struct student studenti[SIZE];
|
|
int hlasy = 0;
|
|
int existuje = 0;
|
|
char vstup[LINE_SIZE];
|
|
char name[LINE_SIZE];
|
|
int velkost_zoznamu = 0; //pocet studentov
|
|
|
|
while (fgets (vstup, LINE_SIZE, stdin) != NULL) {
|
|
//citat input, kontrola ci existuje, pridat hlasy existujucemu zaznamu
|
|
if (sscanf(vstup, "%d %[^\n]", &hlasy, name) != 2) break;
|
|
existuje = 0;
|
|
for (int i = 0; i < velkost_zoznamu; i++) {
|
|
if (strcmp (name, studenti[i].name) == 0) {
|
|
existuje = 1;
|
|
studenti[i].votes += hlasy;
|
|
break;
|
|
}
|
|
}
|
|
if (!existuje) {
|
|
strcpy (studenti[velkost_zoznamu].name, name);
|
|
studenti[velkost_zoznamu].votes = hlasy;
|
|
velkost_zoznamu++;
|
|
}
|
|
}
|
|
|
|
//zoradit abecedne, potom zoradit mena podla poctov hlasov, poposuvat cisla hore
|
|
|
|
//vystup vo formate printf("Vysledky:\n"); for i=0 to pocet_studentov printf("%d %c\n"student[i].votes, student[i].name[j]);
|
|
|
|
return 0;
|
|
} |