refresh
This commit is contained in:
parent
078b4436d6
commit
ad8f78db53
BIN
a1/program.exe
BIN
a1/program.exe
Binary file not shown.
BIN
du1/program.exe
BIN
du1/program.exe
Binary file not shown.
BIN
du2/program.exe
BIN
du2/program.exe
Binary file not shown.
@ -1,36 +1,69 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX_NAME_LENGTH 100
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[100];
|
char name[MAX_NAME_LENGTH];
|
||||||
int golosa;
|
int votes;
|
||||||
} nameandgolosa;
|
} Student;
|
||||||
|
|
||||||
#define MAX_STUDENTS 1000;
|
int compare_students(const void *a, const void *b) {
|
||||||
|
const Student *studentA = (const Student *)a;
|
||||||
|
const Student *studentB = (const Student *)b;
|
||||||
|
|
||||||
int najtistudenta (nameandgolosa students[], int count, const char* name) {
|
if (studentA->votes != studentB->votes) {
|
||||||
for (int i = 0; i < count; i++) {
|
return studentB->votes - studentA->votes; // Сортировка по убыванию голосов
|
||||||
if (strcmp(students[i].name, name) == 0) {
|
} else {
|
||||||
return i;
|
return strcmp(studentA->name, studentB->name); // Лексикографическая сортировка по имени
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare (const void* a, const void* b) {
|
|
||||||
nameandgolosa* studentA = (nameandgolosa*)a;
|
|
||||||
nameandgolosa* studentB = (nameandgolosa*)b;
|
|
||||||
|
|
||||||
if (studentA->golosa != studentB->golosa) {
|
|
||||||
return studentB->golosa - studentA->golosa;
|
|
||||||
}
|
|
||||||
return strcmp(studentA->name, studentB->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
Student students[100];
|
||||||
|
int student_count = 0;
|
||||||
|
char line[256];
|
||||||
|
|
||||||
|
while (fgets(line, sizeof(line), stdin)) {
|
||||||
|
int votes;
|
||||||
|
char name[MAX_NAME_LENGTH];
|
||||||
|
|
||||||
|
if (sscanf(line, "%d %[^\n]", &votes, name) != 2) {
|
||||||
|
break; // Прерываем чтение при неверном формате
|
||||||
|
}
|
||||||
|
|
||||||
|
// Поиск студента в массиве
|
||||||
|
int found = 0;
|
||||||
|
for (int i = 0; i < student_count; i++) {
|
||||||
|
if (strcmp(students[i].name, name) == 0) {
|
||||||
|
students[i].votes += votes;
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если студент не найден, добавляем нового
|
||||||
|
if (!found) {
|
||||||
|
strcpy(students[student_count].name, name);
|
||||||
|
students[student_count].votes = votes;
|
||||||
|
student_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (student_count == 0) {
|
||||||
|
printf("Chyba: nepodarilo sa nacitat ziadny zaznam.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сортировка студентов
|
||||||
|
qsort(students, student_count, sizeof(Student), compare_students);
|
||||||
|
|
||||||
|
// Вывод результатов
|
||||||
|
printf("Vysledky:\n");
|
||||||
|
for (int i = 0; i < student_count; i++) {
|
||||||
|
printf("%d %s\n", students[i].votes, students[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
du4/program.exe
BIN
du4/program.exe
Binary file not shown.
Loading…
Reference in New Issue
Block a user