Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- using namespace std;
- void heapify(vector<pair<string, int>> & mas, int pos, int n)
- {
- while (2 * pos + 1 < n)
- {
- int j = 2 * pos + 1;
- if ((j + 1 < n) && (mas[j + 1] > mas[j]))
- j++;
- if (mas[j] > mas[pos])
- {
- swap(mas[pos], mas[j]);
- pos = j;
- }
- else
- break;
- }
- }
- int main()
- {
- int n;
- cin >> n;
- vector<pair<string, int>> mas;
- string a;
- for (int i = 0; i < n; i++)
- {
- cin >> a;
- mas.push_back(make_pair(a, i));
- }
- for (int i = n - 1; i >= 0; i--)
- heapify(mas, i, n);
- int *ans = new int[n];
- for (int i = 0; i < mas.size(); i++)
- {
- ans[mas[i].second] = i + 1;
- }
- for (int i = 0; i < n; i++)
- {
- cout << ans[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement