funguje
This commit is contained in:
parent
c961194bc3
commit
c34908dce6
@ -32,6 +32,17 @@ int read_students(struct Student students[], int max_students) {
|
||||
char name[MAX_SIZE];
|
||||
// Ak sa nenačítajú dva prvky (počet hlasov a meno), skončíme
|
||||
if (sscanf(line, "%d %99[^\n]", &votes, name) == 2) {
|
||||
// Prejdeme všetkých študentov a ak nájdeme rovnaké meno, pripočítame hlasy
|
||||
int found = 0;
|
||||
for (int i = 0; i < num_students; i++) {
|
||||
if (strcmp(students[i].name, name) == 0) {
|
||||
students[i].votes += votes;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Ak sme nenašli rovnaké meno, pridáme nového študenta
|
||||
if (!found) {
|
||||
strcpy(students[num_students].name, name);
|
||||
students[num_students].votes = votes;
|
||||
num_students++;
|
||||
@ -40,6 +51,7 @@ int read_students(struct Student students[], int max_students) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return num_students;
|
||||
}
|
||||
|
||||
@ -47,7 +59,7 @@ int main() {
|
||||
struct Student students[MAX_STUDENTS];
|
||||
int num_students = read_students(students, MAX_STUDENTS);
|
||||
|
||||
// Zoradíme študentov podľa počtu hlasov
|
||||
// Zoradíme študentov podľa počtu hlasov a mena
|
||||
qsort(students, num_students, sizeof(struct Student), compare);
|
||||
|
||||
// Vypíšeme výsledky
|
||||
|
Loading…
Reference in New Issue
Block a user