Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <Windows.h>
- struct SPORTMAN
- {
- int oc;
- int razbr;
- char Name[255];
- };
- struct COMP
- {
- int judsCount;
- int sportmansCount;
- SPORTMAN sportmans[100];
- };
- void AddSor()
- {
- system("cls");
- COMP comp = { 0 };
- FILE* file = fopen("sorevs.bd", "r+b");
- if (file == NULL)
- {
- file = fopen("sorevs.bd", "w+b");
- if (file == NULL)
- {
- printf("Ошибка открытии файла\n");
- system("pause");
- return;
- }
- }
- printf("Введите количество спортсменов: ");
- scanf("%d", &comp.sportmansCount);
- printf("Введите количество судей: ");
- scanf("%d", &comp.judsCount);
- printf("Введите оценки спортсменов (от 0 до 5)\n\n");
- char buff[255] = { 0 };
- for (int i = 0; i < comp.sportmansCount; i++)
- {
- int min = 7, max = -1;
- bool bMin = false, bMax = false;
- bool skipMinFlag = false, skipMaxFlag = false;
- int oc = 0;
- fgets(buff, 255, stdin);
- printf("Спортсмен №%d\nВведите имя спортсмена: ", i + 1);
- fgets(comp.sportmans[i].Name, 255, stdin);
- if (comp.sportmans[i].Name[strlen(comp.sportmans[i].Name) - 1] == '\n')
- comp.sportmans[i].Name[strlen(comp.sportmans[i].Name) - 1] = '\0';
- for (int j = 0; j < comp.judsCount; j++)
- {
- printf("\tСудья №%d: ", j + 1);
- do scanf("%d", &oc);
- while (oc < 0 || oc > 5);
- if (oc > max)
- max = oc;
- if (oc < min)
- min = oc;
- comp.sportmans[i].oc += oc;
- }
- comp.sportmans[i].oc = comp.sportmans[i].oc - max - min;
- comp.sportmans[i].razbr = max - min;
- }
- fseek(file, 0, SEEK_END);
- fwrite(&comp, sizeof(COMP), 1, file);
- fclose(file);
- }
- void PrintAllSor()
- {
- system("cls");
- FILE* file = fopen("sorevs.bd", "r+b");
- if (file == NULL)
- {
- printf("Ошибка открытия файла\n");
- system("pause");
- return;
- }
- COMP* comp = new COMP;
- fseek(file, 0, SEEK_END);
- int filesize = ftell(file);
- for (unsigned int i = 0; i < filesize; i += sizeof(COMP))
- {
- fseek(file, i, SEEK_SET);
- fread(comp, sizeof(COMP), 1, file);
- printf("\nСоревнование №%d\nКол-во спортсменов: %d\nКол-во судей: %d\n\n", i / sizeof(COMP) + 1, comp->sportmansCount, comp->judsCount);
- SPORTMAN* sportmanMin = new SPORTMAN{ 0 };
- SPORTMAN* sportmanMax = new SPORTMAN{ 0 };
- sportmanMin->razbr = 7;
- sportmanMax->razbr = -1;
- for (int j = 0; j < comp->sportmansCount; j++)
- {
- SPORTMAN* sportman = new SPORTMAN{ 0 };
- int ind = -1;
- for (int k = 0; k < comp->sportmansCount; k++)
- {
- if (comp->sportmans[k].oc > sportman->oc)
- {
- memcpy(sportman, &comp->sportmans[k], sizeof(SPORTMAN));
- ind = k;
- }
- }
- if (sportman->razbr > sportmanMax->razbr)
- memcpy(sportmanMax, sportman, sizeof(SPORTMAN));
- if (sportman->razbr < sportmanMin->razbr)
- memcpy(sportmanMin, sportman, sizeof(SPORTMAN));
- comp->sportmans[ind].oc = 0;
- printf("\t%s : %d\n", sportman->Name, sportman->oc);
- delete sportman;
- sportman = nullptr;
- }
- printf("\nНаибольший разброс у %s\nНаименьший разброс у %s\n",
- sportmanMax->Name, sportmanMin->Name);
- delete sportmanMin; delete sportmanMax;
- sportmanMin = nullptr; sportmanMax = nullptr;
- }
- delete comp;
- comp = nullptr;
- fclose(file);
- system("pause");
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int sel = 5;
- while (sel != 0)
- {
- do
- {
- system("cls");
- printf("1 - Добавить информацию о соревновании\n2 - Вывести все соревнования\n0 - Выход\n");
- scanf("%d", &sel);
- } while (sel < 0 || sel > 2);
- if (sel == 1)
- AddSor();
- else if (sel == 2)
- PrintAllSor();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement