test
This commit is contained in:
parent
0cb54e54df
commit
301029a4cd
@ -26,11 +26,18 @@ int main() {
|
|||||||
int student_count = 0;
|
int student_count = 0;
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
int total_votes = 0;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), stdin)) {
|
while (fgets(line, sizeof(line), stdin)) {
|
||||||
int vote_count;
|
int vote_count;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
sscanf(line, "%d %[^\n]", &vote_count, name);
|
sscanf(line, "%d %[^\n]", &vote_count, name);
|
||||||
|
|
||||||
|
if (student_count == 0) {
|
||||||
|
total_votes = vote_count;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int existing_student_index = -1;
|
int existing_student_index = -1;
|
||||||
for (int i = 0; i < student_count; i++) {
|
for (int i = 0; i < student_count; i++) {
|
||||||
if (strcmp(students[i].name, name) == 0) {
|
if (strcmp(students[i].name, name) == 0) {
|
||||||
@ -56,22 +63,17 @@ int main() {
|
|||||||
students[student_count].vote_count = vote_count;
|
students[student_count].vote_count = vote_count;
|
||||||
student_count++;
|
student_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (student_count == 1) {
|
|
||||||
printf("Vysledky:\n");
|
|
||||||
printf("%d %s\n", students[0].vote_count, students[0].name);
|
|
||||||
free(students[0].name);
|
|
||||||
free(students);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(students, student_count, sizeof(student_t), compare_students);
|
if (student_count == 1) {
|
||||||
|
printf("Vysledky:\n");
|
||||||
printf("Vysledky:\n");
|
printf("%d %s\n", total_votes, students[0].name);
|
||||||
for (int i = 0; i < student_count; i++) {
|
} else {
|
||||||
printf("%d %s\n", students[i].vote_count, students[i].name);
|
qsort(students, student_count, sizeof(student_t), compare_students);
|
||||||
|
printf("Vysledky:\n");
|
||||||
|
for (int i = 0; i < student_count; i++) {
|
||||||
|
printf("%d %s\n", students[i].vote_count, students[i].name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < student_count; i++) {
|
for (int i = 0; i < student_count; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user