Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. typedef struct
  2. {
  3. char name[10];
  4. int vip;
  5. int vuz;
  6. float pr;
  7. } school;
  8.  
  9. void IndexSort(school arr[], int n, int *B)
  10. {
  11. int i,j,t = 0;
  12. for(i = 0; i < n; i++)
  13. {
  14. B[i] = i;
  15. }
  16. for (i = n-2; i>=0; --i)
  17. {
  18. for (j = n-1; j>0; --j)
  19. {
  20. if (arr[i].pr < arr[j].pr)
  21. {
  22. t=B[i];
  23. B[i]=B[j];
  24. B[j]=t;
  25. }
  26. }
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. int i, j, t, n;
  33. int B[n];
  34. school S;
  35.  
  36. cout << "Input amount of schools: ";
  37. cin >> n;
  38. cout << endl;
  39.  
  40. school* arr = new school[n];
  41.  
  42. for (i = 0; i < n; i++)
  43. {
  44. cout << "Input school name: ";
  45. cin >> arr[i].name;
  46. cout << "Input amount of graduate school:";
  47. cin >> arr[i].vip;
  48. cout << "Input amount of already students:";
  49. cin >> arr[i].vuz;
  50. if (arr[i].vip < arr[i].vuz)
  51. {
  52. cout << "You did mistake, try again " << endl;
  53. break;
  54. }
  55. }
  56.  
  57. for(i = 0; i < n; i++)
  58. {
  59. S.pr = ((float)S.vip/(float)S.vuz)*100;
  60. arr[i] = S;
  61. }
  62.  
  63. IndexSort(arr, n, B);
  64.  
  65. for (i = 0; i < n; i++)
  66. cout << arr[i].name << " " << arr[i].vip << " " << arr[i].vuz << " ";
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement