#include <iostream> #include <vector> #include <cstdint> #include <algorithm> #include <random> typedef std::vector<std::intmax_t> DType; DType MakeVector(std::size_t N) { DType R; for (std::size_t i = 0; i < N; i++) { R.push_back(i); } return R; } /** / DType MakeHoge(const DType& D) { DType Idx =MakeVector(D.size()); for (std::size_t i = 0; i < D.size()-1; i++) { for (std::size_t j = i+1; j < D.size(); j++) { if (D[Idx[i]] > D[Idx[j]]) { std::swap(Idx[i], Idx[j]); } } } return Idx; } /**/ DType MakeHoge(const DType& D) { DType Idx =MakeVector(D.size()); std::sort(Idx.begin(), Idx.end(), [&](auto& A, auto& B) {return D[A] < D[B]; }); return Idx; } int main() { DType D = MakeVector(16); std::minstd_rand mr; std::shuffle(D.begin(), D.end(),mr); DType Idx = MakeHoge(D); for (std::size_t i = 0; i < D.size(); i++) { std::cout << D[i] << ','; } std::cout << std::endl; for (std::size_t i = 0; i < Idx.size(); i++) { std::cout << Idx[i] << ','; } std::cout << std::endl; for (std::size_t i = 0; i < D.size(); i++) { std::cout << D[Idx[i]] << ','; } std::cout << std::endl; return 0; }
Standard input is empty
5,11,10,4,0,14,12,9,8,13,1,7,6,3,2,15, 4,10,14,13,3,0,12,11,8,7,2,1,6,9,5,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,