Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. struct Student
  8. {
  9. string name;
  10. int group;
  11. int number;
  12.  
  13. Student()
  14. {
  15. this->name = "";
  16. this->group = 0;
  17. this->number = 0;
  18. }
  19.  
  20. Student(string name, int group,int number)
  21. {
  22. this->name = name;
  23. this->group = group;
  24. this->number = number;
  25. }
  26. };
  27.  
  28.  
  29. queue<int> printDistinct(int arr[], int n,queue<int> q)
  30. {
  31.  
  32. for (int i = 0; i < n; i++)
  33. {
  34.  
  35. int j;
  36. for (j = 0; j < i; j++)
  37. if (arr[i] == arr[j])
  38. break;
  39.  
  40.  
  41. if (i == j)
  42. q.push(arr[i]);
  43. }
  44. return q;
  45. }
  46.  
  47. int main()
  48. {
  49. int N;
  50. cin >> N;
  51. int M;
  52. cin >> M;
  53.  
  54.  
  55. queue<Student*> q;
  56. queue<Student*> q_copy;
  57. queue<int> q_groups;
  58. queue<Student*>* arr_queues = new queue<Student*>[M + 1];
  59.  
  60. string* arr_name = new string[N];
  61. int* arr_group = new int[N];
  62. int number = 0;
  63. int counter = 2;
  64.  
  65.  
  66.  
  67.  
  68.  
  69. for (int i = 0; i < N; i++)
  70. {
  71. cin >> arr_name[i];
  72. cin >> arr_group[i];
  73.  
  74. Student* st = new Student(arr_name[i], arr_group[i], number);
  75. q.push(st);
  76. number++;
  77.  
  78. }
  79. number = 0;
  80.  
  81. q_groups = printDistinct(arr_group, N,q_groups);
  82.  
  83.  
  84. int j = 0;
  85.  
  86.  
  87. for (int i = 0; i <= M; i++)
  88. {
  89. if (arr_group[j] == i)
  90. {
  91. Student* st = new Student(arr_name[j], arr_group[j],number);
  92. arr_queues[i].push(st);
  93. number++;
  94.  
  95. j++;
  96. if (j == N)
  97. break;
  98. i = 0;
  99. }
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. while (!q.empty())
  107. {
  108.  
  109. if (q.front()->number < counter )
  110. {
  111.  
  112. if (!arr_queues[q.front()->group].empty())
  113. {
  114.  
  115. //cout << arr_queues[q.front()->group].front()->name << " " << arr_queues[q.front()->group].front()->group <<
  116. //" " << arr_queues[q.front()->group].front()->number << endl;
  117.  
  118. while ( !arr_queues[q.front()->group].empty())
  119. {
  120. if (arr_queues[q.front()->group].front()->number < counter)
  121. {
  122. q_copy.push(arr_queues[q.front()->group].front());
  123. }
  124. else
  125. break;
  126.  
  127. arr_queues[q.front()->group].pop();
  128.  
  129. }
  130.  
  131. }
  132. else
  133. {
  134. if(!q_groups.empty())
  135. q_groups.pop();
  136.  
  137. }
  138. counter += 2;
  139. q.pop();
  140. }
  141.  
  142.  
  143.  
  144. }
  145.  
  146. counter = 2;
  147.  
  148. while (!q_copy.empty())
  149. {
  150. cout << q_copy.front()->name << " " << q_copy.front()->number << " " << counter << endl;
  151. q_copy.pop();
  152. counter += 2;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. int _;
  163. cin >> _;
  164. return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement