#include <iostream> #include <vector> #include <random> #include <algorithm> typedef std::vector<std::vector<int>> vec2; vec2 MakeData01(int W, int H){ vec2 vec{ { 1, 5, 3, 4, }, { 0, 4, 1, 0, }, { 7, 2, 3, 1, }, }; return vec; } vec2 MakeData02(int W, int H){ vec2 vec; std::random_device rd; std::mt19937_64 mt(rd()*rd());//手抜き std::uniform_int_distribution<int> uid(0, 999); for (int i = 0; i < H; i++){ vec.push_back(std::vector<int>()); for (int j = 0; j < W; j++) { vec[i].push_back(uid(mt)); } } return vec; } bool BubbleSortV(vec2& vec, std::size_t P){ for (std::size_t i = 0; i < vec.size(); i++){ for (std::size_t j= i; j < vec.size(); j++){ if (vec[i][P]>vec[j][P])std::swap(vec[i][P], vec[j][P]); } } return true; } bool MakeHoge(vec2& Vec){ for (auto& o : Vec) std::sort(o.begin(), o.end()); for (std::size_t i = 0; i < Vec[0].size(); i++) BubbleSortV(Vec, i); return true; } bool Show(vec2 vec){ std::cout << "Result;"<<std::endl; for (auto& oo : vec){ for (auto& o : oo){ std::cout << o << ','; } std::cout <<std::endl; } std::cout <<std::endl; return true; } int main(){ vec2 D; D = MakeData01(4, 3); MakeHoge(D); Show(D); D = MakeData02(4, 3); MakeHoge(D); Show(D); D = MakeData02(16, 15); MakeHoge(D); Show(D); return 0; }
Standard input is empty
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,