Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //найти самого успевающего студента заданной группы
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <locale.h>
- #define n 8
- struct faculty
- {
- char A[20];
- char group[10];
- float ball;
- };
- void main()
- {
- setlocale(LC_ALL, "Rus");
- int i = 1, k = 0, j = 0, s; float b; char g[10];
- faculty F[n], f;
- FILE *fi;
- fopen_s(&fi, "input.txt", "r");
- fscanf_s(fi, "%s %s %f", &F[0].A, 20, &F[0].group, 10, &F[0].ball);
- while (i<n && fscanf_s(fi, "%s %s %f", &f.A, 20, &f.group, 10, &f.ball) != EOF)
- {
- while (strcmp(f.group, F[j].group) > 0 && j<i) j++;
- k = i;
- while (k > j)
- {
- F[k] = F[k - 1];
- k--;
- }
- F[j] = f;
- j = 0; i++;
- }
- if (i == n && fscanf_s(fi, "%s", &f.A, 20) != EOF) printf("\nВ таблице недостаточно памяти");
- else
- {
- printf("Введите группу: ");
- scanf_s("%s", &g, 10);
- for (int k = 0; k < i; k++) printf("%s %s %.2f\n", F[k].A, F[k].group, F[k].ball);
- k = 0;
- while (strcmp(F[k].group, g) != 0 && k < i) k++;
- if (k == i) printf("\nТакой группы нет");
- else
- {
- b = F[k].ball;
- s = k;
- k++;
- while (strcmp(F[k].group, g) == 0 && k < i)
- {
- if (F[k].ball > b) { b = F[k].ball; s = k; }
- k++;
- }
- }
- printf("\n%s %s %.2f", F[s].A, F[s].group, F[s].ball);
- }
- fclose(fi);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement