fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <algorithm>
  5.  
  6. typedef std::vector<std::vector<int>> vec2;
  7.  
  8. vec2 MakeData01(int W, int H){
  9. vec2 vec{
  10. { 1, 5, 3, 4, },
  11. { 0, 4, 1, 0, },
  12. { 7, 2, 3, 1, },
  13. };
  14.  
  15. return vec;
  16. }
  17.  
  18. vec2 MakeData02(int W, int H){
  19. vec2 vec;
  20. std::random_device rd;
  21. std::mt19937_64 mt(rd()*rd());//手抜き
  22. std::uniform_int_distribution<int> uid(0, 999);
  23.  
  24. for (int i = 0; i < H; i++){
  25. vec.push_back(std::vector<int>());
  26. for (int j = 0; j < W; j++)
  27. {
  28. vec[i].push_back(uid(mt));
  29. }
  30. }
  31.  
  32. return vec;
  33. }
  34.  
  35. bool BubbleSortV(vec2& vec, std::size_t P){
  36. for (std::size_t i = 0; i < vec.size(); i++){
  37. for (std::size_t j= i; j < vec.size(); j++){
  38. if (vec[i][P]>vec[j][P])std::swap(vec[i][P], vec[j][P]);
  39. }
  40. }
  41. return true;
  42. }
  43.  
  44. bool MakeHoge(vec2& Vec){
  45. for (auto& o : Vec) std::sort(o.begin(), o.end());
  46. for (std::size_t i = 0; i < Vec[0].size(); i++) BubbleSortV(Vec, i);
  47.  
  48. return true;
  49. }
  50.  
  51. bool Show(vec2 vec){
  52. std::cout << "Result;"<<std::endl;
  53. for (auto& oo : vec){
  54. for (auto& o : oo){
  55. std::cout << o << ',';
  56. }
  57. std::cout <<std::endl;
  58. }
  59. std::cout <<std::endl;
  60. return true;
  61. }
  62.  
  63. int main(){
  64. vec2 D;
  65.  
  66. D = MakeData01(4, 3);
  67. MakeHoge(D);
  68. Show(D);
  69. D = MakeData02(4, 3);
  70. MakeHoge(D);
  71. Show(D);
  72. D = MakeData02(16, 15);
  73. MakeHoge(D);
  74. Show(D);
  75. return 0;
  76.  
  77. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
Result;
0,0,1,4,
1,2,3,5,
1,3,4,7,

Result;
94,164,420,646,
119,211,568,669,
217,505,634,724,

Result;
7,21,38,54,125,221,294,330,400,426,505,510,526,670,737,900,
14,23,49,111,164,274,298,391,446,504,559,590,651,674,792,909,
14,48,53,128,197,281,307,393,466,513,584,627,745,775,833,911,
20,53,63,131,227,290,316,412,488,520,588,663,748,810,839,948,
23,56,126,171,241,308,359,414,491,532,595,710,761,812,905,966,
32,64,126,189,245,315,379,425,503,544,633,747,776,859,911,969,
33,66,144,190,271,339,396,454,507,583,649,763,836,876,917,969,
39,67,145,190,282,354,449,482,531,612,699,803,851,878,931,977,
42,68,145,205,289,387,453,483,548,641,705,807,855,896,935,977,
46,70,146,217,316,407,463,508,590,644,723,815,863,908,941,979,
47,94,191,249,335,411,467,515,608,711,751,820,867,909,943,985,
49,102,192,288,346,488,502,625,695,728,752,833,873,910,944,987,
56,139,210,305,373,531,588,694,732,733,776,839,893,915,950,989,
86,191,284,335,403,556,619,700,750,757,790,858,895,940,961,992,
178,379,409,416,463,586,630,706,761,764,815,910,934,942,976,993,