Advertisement
Heart_Under_Blade

№3

Nov 6th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     vector<vector<int>>VEC;
  11.     int num = 1, value = 1;
  12.  
  13.     while (num || value)
  14.     {
  15.         cout << "num: ";
  16.         cin >> num;
  17.         cout << "value: ";
  18.         cin >> value;
  19.        
  20.         if (VEC.size() <= num)
  21.             VEC.resize(num + 1);
  22.        
  23.         VEC[num].push_back(value);
  24.  
  25.     }
  26.    
  27.     cout << endl;
  28.  
  29.     cout << "unsorted vector:  " << endl;
  30.     for (int i = 0; i < VEC.size(); i++)
  31.         for (int j = 0; j < VEC[i].size(); j++)
  32.             cout << "i: " << i << " j: " << j << " value= " << VEC[i][j] << " " << endl;
  33.     for (int i = 0; i < VEC.size(); i++)
  34.         sort(VEC[i].begin(), VEC[i].end());
  35.  
  36.     cout << "\n sorted vector:  " << endl;
  37.     for (int i = 0; i < VEC.size(); i++)
  38.         for (int j = 0; j < VEC[i].size(); j++)
  39.             cout << "i: " << i << " j: " << j << " value= " << VEC[i][j] << " " << endl;
  40.  
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement