fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7. std::vector<std::vector<int>> vvi = {{1, 5, 3, 4}, {0, 4, 1, 0}, {7, 2, 3, 1}};
  8. int mx, my;
  9.  
  10. mx = vvi[0].size();
  11. my = vvi.size();
  12. std::cout << "X方向のサイズ = " << mx << ", Y方向のサイズ = " << my << std::endl;
  13.  
  14. std::vector<int> wrk;
  15.  
  16. for (std::vector<int>& v : vvi)
  17. std::copy(std::begin(v), std::end(v), std::back_inserter(wrk));
  18.  
  19. std::for_each(std::begin(wrk), std::end(wrk), [](int i){ std::cout << i << ' '; });
  20. std::cout << std::endl;
  21. std::sort(std::begin(wrk), std::end(wrk));
  22. std::for_each(std::begin(wrk), std::end(wrk), [](int i){ std::cout << i << ' '; });
  23. std::cout << std::endl;
  24.  
  25. for (int i = 0; i < my; i++) {
  26. for (int j = 0; j < mx; j++) {
  27. vvi[i][j] = wrk[i * mx + j];
  28. std::cout << vvi[i][j] << ' ';
  29. }
  30. std::cout << std::endl;
  31. }
  32. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
X方向のサイズ = 4, Y方向のサイズ = 3
1 5 3 4 0 4 1 0 7 2 3 1 
0 0 1 1 1 2 3 3 4 4 5 7 
0 0 1 1 
1 2 3 3 
4 4 5 7