JuliaMelkozerova

Сортировка ключ-значение

Oct 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int i, j, N, k;
  12.     cin >> N >> k;
  13.     map<string, vector<int>> mymap;
  14.     string Name;
  15.     vector<int> a (k);
  16.    
  17.     for (i = 0; i < N; i++){
  18.         cin >> Name;
  19.         for (j = 0; j < k; j++) cin >> a[j];
  20.         mymap.insert(pair<string, vector<int>> (Name, a));    
  21.     }
  22.    
  23.     vector<int> p (k);
  24.     for (j = 0; j < k; j++) cin >> p[j];
  25.    
  26.     sort(p.begin(), p.end());
  27.     for (j = 0; j < k; j++) cout << p[j] << '\t';
  28.     cout << endl;
  29.    
  30.     for (auto elem: mymap) {
  31.         cout << elem.first << '\t';
  32.         for (j = 0; j < k; j++) cout << elem.second[j] << '\t';
  33.         cout << endl;
  34.     }
  35. }
Add Comment
Please, Sign In to add comment