Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <queue>
- using namespace std;
- #define MAX 100
- struct k
- {
- int num, want;
- };
- bool D(k p1, k p2)
- {
- return p1.want < p2.want;
- }
- int main()
- {
- int n, prom;
- map <int, vector<int>> teams;
- vector <k> promg;
- vector <int> sameteam;
- k promk;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> prom;
- promk.num = i;
- promk.want = prom;
- promg.push_back(promk);
- }
- sort(promg.begin(), promg.end(), D);
- int lastwant= promg.begin()->want;
- sameteam.push_back(promg.begin()->num);
- int allteam=0;
- for (auto i = promg.begin()+1; i != promg.end(); i++)
- {
- if (lastwant != i->want)
- {
- if (sameteam.size() == lastwant)
- {
- allteam++;
- teams[lastwant] = sameteam;
- }
- else
- if (sameteam.size() > lastwant&&sameteam.size() < i->want)
- {
- teams[sameteam.size()] = sameteam;
- allteam++;
- }
- lastwant = i->want;
- }
- sameteam.push_back(i->num);
- }
- if (sameteam.size() == lastwant)
- {
- allteam++;
- teams[lastwant] = sameteam;
- }
- else
- if (sameteam.size() > lastwant)
- {
- teams[sameteam.size()] = sameteam;
- allteam++;
- }
- cout << allteam << endl;
- for (auto i = teams.begin(); i != teams.end(); i++)
- {
- cout << i->first << " ";
- for (auto j = i->second.rbegin(); j != i->second.rend(); j++)
- cout << *j << " ";
- cout << endl;
- }
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment