abubaca

Untitled

Dec 27th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <utility>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. bool predi(const pair< char, int > &a, const pair< char, int > &b)
  10. {
  11.   return a.second < b.second;
  12. }
  13.  
  14. bool predd(const pair< char, double > &a, const pair< char, double > &b)
  15. {
  16.   return a.second < b.second;
  17. }
  18.  
  19. int main()
  20. {
  21.   map <int, char> order;
  22.   map <char, double> count;
  23.   map <char, int> avrg;
  24.   int m, n;
  25.   cin >> n >> m;
  26.   char temp1;
  27.   double temp2;
  28.   for (int i = 0; i < n; i++)
  29.   {
  30.     cin >> temp1 >> temp2;
  31.     order[i] = temp1;
  32.     count[temp1] = temp2;
  33.   }
  34.   map <char, int> ::iterator curr, past;
  35.   for (int i = 0; i < m; i++)
  36.   {
  37.     cin >> temp1;
  38.     curr = avrg.find(temp1);
  39.     past = avrg.end();
  40.     if (curr == past)
  41.       avrg[temp1] = 1;
  42.     else
  43.       (curr->second)++;
  44.   }
  45.   vector< pair < char, double > > source(count.begin(), count.end());
  46.   vector< pair < char, int > > dest(avrg.begin(), avrg.end());
  47.   sort(source.begin(), source.end(), predd);
  48.   sort(dest.begin(), dest.end(), predi);
  49.   map <char, char> loc;
  50.   for (int i = 0; i < source.size(); i++)
  51.   {
  52.     loc[source[i].first] = dest[i].first;
  53.   }
  54.   for (map <int, char> ::iterator itr = order.begin(); itr != order.end(); itr++)
  55.   {
  56.     cout << loc.find(itr->second)->second << endl;
  57.   }
  58.   //system("pause");
  59. }
Advertisement
Add Comment
Please, Sign In to add comment