Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <string>
- using namespace std;
- struct Student
- {
- string name;
- int group;
- int number;
- Student()
- {
- this->name = "";
- this->group = 0;
- this->number = 0;
- }
- Student(string name, int group,int number)
- {
- this->name = name;
- this->group = group;
- this->number = number;
- }
- };
- queue<int> printDistinct(int arr[], int n,queue<int> q)
- {
- for (int i = 0; i < n; i++)
- {
- int j;
- for (j = 0; j < i; j++)
- if (arr[i] == arr[j])
- break;
- if (i == j)
- q.push(arr[i]);
- }
- return q;
- }
- int main()
- {
- int N;
- cin >> N;
- int M;
- cin >> M;
- queue<Student*> q;
- queue<Student*> q_copy;
- queue<int> q_groups;
- queue<Student*>* arr_queues = new queue<Student*>[M + 1];
- string* arr_name = new string[N];
- int* arr_group = new int[N];
- int number = 0;
- int counter = 2;
- for (int i = 0; i < N; i++)
- {
- cin >> arr_name[i];
- cin >> arr_group[i];
- Student* st = new Student(arr_name[i], arr_group[i], number);
- q.push(st);
- number++;
- }
- number = 0;
- q_groups = printDistinct(arr_group, N,q_groups);
- int j = 0;
- for (int i = 0; i <= M; i++)
- {
- if (arr_group[j] == i)
- {
- Student* st = new Student(arr_name[j], arr_group[j],number);
- arr_queues[i].push(st);
- number++;
- j++;
- if (j == N)
- break;
- i = 0;
- }
- }
- while (!q.empty())
- {
- if (q.front()->number < counter )
- {
- if (!arr_queues[q.front()->group].empty())
- {
- //cout << arr_queues[q.front()->group].front()->name << " " << arr_queues[q.front()->group].front()->group <<
- //" " << arr_queues[q.front()->group].front()->number << endl;
- while ( !arr_queues[q.front()->group].empty())
- {
- if (arr_queues[q.front()->group].front()->number < counter)
- {
- q_copy.push(arr_queues[q.front()->group].front());
- }
- else
- break;
- arr_queues[q.front()->group].pop();
- }
- }
- else
- {
- if(!q_groups.empty())
- q_groups.pop();
- }
- counter += 2;
- q.pop();
- }
- }
- counter = 2;
- while (!q_copy.empty())
- {
- cout << q_copy.front()->name << " " << q_copy.front()->number << " " << counter << endl;
- q_copy.pop();
- counter += 2;
- }
- int _;
- cin >> _;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement