fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <random>
  6.  
  7. typedef std::vector<std::intmax_t> DType;
  8.  
  9. DType MakeVector(std::size_t N) {
  10. DType R;
  11. for (std::size_t i = 0; i < N; i++) {
  12. R.push_back(i);
  13. }
  14. return R;
  15. }
  16. /** /
  17. DType MakeHoge(const DType& D) {
  18.  
  19. DType Idx =MakeVector(D.size());
  20.  
  21. for (std::size_t i = 0; i < D.size()-1; i++) {
  22. for (std::size_t j = i+1; j < D.size(); j++) {
  23. if (D[Idx[i]] > D[Idx[j]]) {
  24. std::swap(Idx[i], Idx[j]);
  25. }
  26. }
  27. }
  28.  
  29. return Idx;
  30. }
  31. /**/
  32. DType MakeHoge(const DType& D) {
  33.  
  34. DType Idx =MakeVector(D.size());
  35.  
  36. std::sort(Idx.begin(), Idx.end(), [&](auto& A, auto& B) {return D[A] < D[B]; });
  37.  
  38. return Idx;
  39. }
  40. int main() {
  41. DType D = MakeVector(16);
  42. std::minstd_rand mr;
  43.  
  44. std::shuffle(D.begin(), D.end(),mr);
  45.  
  46. DType Idx = MakeHoge(D);
  47.  
  48. for (std::size_t i = 0; i < D.size(); i++) {
  49. std::cout << D[i] << ',';
  50. }
  51. std::cout << std::endl;
  52. for (std::size_t i = 0; i < Idx.size(); i++) {
  53. std::cout << Idx[i] << ',';
  54. }
  55. std::cout << std::endl;
  56. for (std::size_t i = 0; i < D.size(); i++) {
  57. std::cout << D[Idx[i]] << ',';
  58. }
  59. std::cout << std::endl;
  60.  
  61. return 0;
  62.  
  63. }
Success #stdin #stdout 0s 4480KB
stdin
Standard input is empty
stdout
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,