Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <utility>
- #include <map>
- using namespace std;
- bool predi(const pair< char, int > &a, const pair< char, int > &b)
- {
- return a.second < b.second;
- }
- bool predd(const pair< char, double > &a, const pair< char, double > &b)
- {
- return a.second < b.second;
- }
- int main()
- {
- map <int, char> order;
- map <char, double> count;
- map <char, int> avrg;
- int m, n;
- cin >> n >> m;
- char temp1;
- double temp2;
- for (int i = 0; i < n; i++)
- {
- cin >> temp1 >> temp2;
- order[i] = temp1;
- count[temp1] = temp2;
- }
- map <char, int> ::iterator curr, past;
- for (int i = 0; i < m; i++)
- {
- cin >> temp1;
- curr = avrg.find(temp1);
- past = avrg.end();
- if (curr == past)
- avrg[temp1] = 1;
- else
- (curr->second)++;
- }
- vector< pair < char, double > > source(count.begin(), count.end());
- vector< pair < char, int > > dest(avrg.begin(), avrg.end());
- sort(source.begin(), source.end(), predd);
- sort(dest.begin(), dest.end(), predi);
- map <char, char> loc;
- for (int i = 0; i < source.size(); i++)
- {
- loc[source[i].first] = dest[i].first;
- }
- for (map <int, char> ::iterator itr = order.begin(); itr != order.end(); itr++)
- {
- cout << loc.find(itr->second)->second << endl;
- }
- //system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment