i need a break / hotove pridavanie studentov do struktury asi
This commit is contained in:
parent
4747e7ed97
commit
486e393121
@ -1,4 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SIZE 100
|
||||
|
||||
@ -9,11 +11,33 @@ struct student {
|
||||
|
||||
int main() {
|
||||
|
||||
//pomocne
|
||||
//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 podla poctu hlasov, potom zoradit skupiny podla mena ak sa najde skupina viacerych s rovnakym poctom hlasov
|
||||
//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]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user