Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. //найти самого успевающего студента заданной группы
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <locale.h>
  6. #define n 8
  7.  
  8. struct faculty
  9. {
  10. char A[20];
  11. char group[10];
  12. float ball;
  13. };
  14.  
  15. void main()
  16. {
  17. setlocale(LC_ALL, "Rus");
  18. int i = 1, k = 0, j = 0, s; float b; char g[10];
  19. faculty F[n], f;
  20.  
  21. FILE *fi;
  22. fopen_s(&fi, "input.txt", "r");
  23.  
  24. fscanf_s(fi, "%s %s %f", &F[0].A, 20, &F[0].group, 10, &F[0].ball);
  25. while (i<n && fscanf_s(fi, "%s %s %f", &f.A, 20, &f.group, 10, &f.ball) != EOF)
  26. {
  27.  
  28. while (strcmp(f.group, F[j].group) > 0 && j<i) j++;
  29. k = i;
  30. while (k > j)
  31. {
  32. F[k] = F[k - 1];
  33. k--;
  34. }
  35. F[j] = f;
  36. j = 0; i++;
  37. }
  38.  
  39. if (i == n && fscanf_s(fi, "%s", &f.A, 20) != EOF) printf("\nВ таблице недостаточно памяти");
  40. else
  41. {
  42. printf("Введите группу: ");
  43. scanf_s("%s", &g, 10);
  44. for (int k = 0; k < i; k++) printf("%s %s %.2f\n", F[k].A, F[k].group, F[k].ball);
  45. k = 0;
  46. while (strcmp(F[k].group, g) != 0 && k < i) k++;
  47. if (k == i) printf("\nТакой группы нет");
  48. else
  49. {
  50. b = F[k].ball;
  51. s = k;
  52. k++;
  53. while (strcmp(F[k].group, g) == 0 && k < i)
  54. {
  55. if (F[k].ball > b) { b = F[k].ball; s = k; }
  56. k++;
  57. }
  58. }
  59. printf("\n%s %s %.2f", F[s].A, F[s].group, F[s].ball);
  60. }
  61.  
  62. fclose(fi);
  63. _getch();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement