Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct Student{
  9. string ident;
  10. float grades;
  11. int meters, month;
  12. unsigned int number;
  13. };
  14.  
  15. void Sortowanie (Student tab[], unsigned n, char p[] ){
  16. Student temp;
  17. switch(p[0]){
  18. case 'm':
  19. for(unsigned int i=n-1; i>0; i--){
  20. unsigned int max =0;
  21. for(unsigned int j=1; j <= i ;j++){
  22. if (tab[max].month<tab[j].month)
  23. max = j ;
  24. else if (tab[max].month == tab[j].month){
  25. if (p[1] == 's'){
  26. if (tab[max].grades<tab[j].grades)
  27. max = j;
  28. else if (tab[max].grades == tab[j].grades){
  29. if(tab[max].meters<tab[j].meters)
  30. max = j;
  31. else if (tab[max].meters == tab[j].meters){
  32. if(tab[max].number>tab[j].number)
  33. max = j;
  34. }
  35. }
  36. }
  37. else if (p[1] == 'd'){
  38. if (tab[max].meters<tab[j].meters)
  39. max = j;
  40. else if (tab[max].meters == tab[j].meters){
  41. if(tab[max].grades<tab[j].grades)
  42. max = j;
  43. else if (tab[max].grades == tab[j].grades){
  44. if(tab[max].ident<tab[j].ident)
  45. max = j;
  46. }
  47. }
  48. }
  49. }
  50. temp = tab[i];
  51. tab[i] = tab[max];
  52. tab[max]=temp;
  53. }
  54. }
  55. break;
  56. case 's':
  57. for(unsigned int i=n-1; i>0; i--){
  58. unsigned int max =0;
  59. for(unsigned int j=1; j <= i ;j++){
  60. if (tab[max].grades<tab[j].grades)
  61. max = j ;
  62. else if (tab[max].grades == tab[j].grades){
  63. if (p[1] == 'm'){
  64. if (tab[max].month<tab[j].month)
  65. max = j;
  66. else if (tab[max].month == tab[j].month){
  67. if(tab[max].meters<tab[j].meters)
  68. max = j;
  69. else if (tab[max].meters == tab[j].meters){
  70. if(tab[max].ident>tab[j].ident)
  71. max = j;
  72. }
  73. }
  74. }
  75. else if (p[1] == 'd'){
  76. if (tab[max].meters<tab[j].meters)
  77. max = j;
  78. else if (tab[max].meters == tab[j].meters){
  79. if(tab[max].month<tab[j].month)
  80. max = j;
  81. else if (tab[max].month == tab[j].month){
  82. if(tab[max].ident<tab[j].ident)
  83. max = j;
  84. }
  85. }
  86. }
  87. }
  88. temp = tab[i];
  89. tab[i] = tab[max];
  90. tab[max]=temp;
  91. }
  92. }
  93. break;
  94. case 'd':
  95. for(unsigned int i=n-1; i>0; i--){
  96. unsigned int max =0;
  97. for(unsigned int j=1; j <= i ;j++){
  98. if (tab[max].meters<tab[j].meters)
  99. max = j ;
  100. else if (tab[max].meters == tab[j].meters){
  101. if (p[1] == 'm'){
  102. if (tab[max].month<tab[j].month)
  103. max = j;
  104. else if (tab[max].month == tab[j].month){
  105. if(tab[max].grades<tab[j].grades)
  106. max = j;
  107. else if (tab[max].grades == tab[j].grades){
  108. if(tab[max].ident>tab[j].ident)
  109. max = j;
  110. }
  111. }
  112. }
  113. else if (p[1] == 's'){
  114. if (tab[max].grades<tab[j].grades)
  115. max = j;
  116. else if (tab[max].grades == tab[j].grades){
  117. if(tab[max].month<tab[j].month)
  118. max = j;
  119. else if (tab[max].month == tab[j].month){
  120. if(tab[max].ident<tab[j].ident)
  121. max = j;
  122. }
  123. }
  124. }
  125. }
  126. temp = tab[i];
  127. tab[i] = tab[max];
  128. tab[max]=temp;
  129. }
  130. }
  131. break;
  132. }
  133. }
  134.  
  135.  
  136. int main()
  137. {
  138. int n;
  139. cin >> n;
  140. if (n<1 || n>1000000) return 0;
  141. Student Boys[n];
  142. Student Girls[n];
  143. Student temp;
  144. char parameters[3];
  145. cin >> parameters[0] >> parameters[1] >> parameters[2];
  146. for (int i = 0; i<n; i++){
  147. cin >> Girls[i].ident >> Girls[i].grades >> Girls[i].meters >> Girls[i].month >>
  148. Boys[i].ident >> Boys[i].grades >> Boys[i].meters >> Boys[i].month;
  149. Girls[i].number = i;
  150. Boys[i].number = i;
  151. }
  152. Sortowanie(Girls,n,parameters);
  153. Sortowanie(Boys,n,parameters);
  154. for (int i = n-1; i>-1; i--){
  155. cout << Girls[i].ident << " " << Boys[i].ident << " ";
  156. }
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement