#include <iostream> #include <vector> #include <cstdint> #include <algorithm> #include <random> typedef std::vector<std::intmax_t> DType; DType MakeVector(const std::size_t& N,const unsigned int& S=0) { std::mt19937 mt(S); std::uniform_int_distribution<std::intmax_t> ui(0, N); DType R; for (std::size_t i = 0; i < N; i++) { R.push_back(ui(mt)); } return R; } DType OddSort(DType D) { for (std::size_t i = 0; i < D.size(); i++) { if (i % 2 == 0) { continue; } for (std::size_t j = i+1; j < D.size(); j++) { if (j % 2 == 0) { continue; } if (D[i] > D[j]) { std::swap(D[i], D[j]); } } } return D; } int main() { DType D; DType R; D = MakeVector(15); R = OddSort(D); for (auto& o : D) { std::cout << o << ','; } std::cout << std::endl; for (auto& o : R) { std::cout << o << ','; } std::cout << std::endl; for (std::size_t i = 1; i < R.size(); i += 2) { std::cout << R[i]<<','; } std::cout << std::endl; return 0; }
Standard input is empty