MaximCherchuk

C

May 31st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /*
  8.  * File:   main.cpp
  9.  * Author: maxim
  10.  *
  11.  * Created on May 31, 2016, 8:26 PM
  12.  */
  13.  
  14. #include <vector>
  15. #include <iostream>
  16. #include <algorithm>
  17. using namespace std;
  18.  
  19. bool cmp(vector<int> a, vector<int> b) {
  20.     if(a.size() == b.size()) {
  21.         return a < b;
  22.     } else {
  23.         return a.size() < b.size();
  24.     }
  25. }
  26.  
  27. int main(int argc, char** argv) {
  28.     vector<int> a1{1};
  29.     vector<int> a2{1, 2};
  30.     vector<int> a3{1, 2, 3};
  31.     vector<int> a4{2, 3};
  32.     vector<int> a5{5, 6};
  33.     vector<vector<int> > v{a1, a2, a3, a4, a5};
  34.     sort(v.begin(), v.end(), cmp);
  35.     for(int i = 0; i < 5; ++i) {
  36.         for(int j = 0; j < v[i].size(); ++j) {
  37.             cout << v[i][j] << ' ';
  38.         }
  39.         cout << endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment