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(const std::size_t& N,const unsigned int& S=0) {
  10. std::mt19937 mt(S);
  11. std::uniform_int_distribution<std::intmax_t> ui(0, N);
  12.  
  13. DType R;
  14.  
  15. for (std::size_t i = 0; i < N; i++) {
  16. R.push_back(ui(mt));
  17. }
  18.  
  19. return R;
  20. }
  21.  
  22. DType OddSort(DType D) {
  23.  
  24. for (std::size_t i = 0; i < D.size(); i++) {
  25. if (i % 2 == 0) { continue; }
  26. for (std::size_t j = i+1; j < D.size(); j++) {
  27. if (j % 2 == 0) { continue; }
  28.  
  29. if (D[i] > D[j]) {
  30. std::swap(D[i], D[j]);
  31. }
  32. }
  33. }
  34. return D;
  35. }
  36.  
  37. int main() {
  38. DType D;
  39. DType R;
  40. D = MakeVector(15);
  41.  
  42. R = OddSort(D);
  43.  
  44. for (auto& o : D) {
  45. std::cout << o << ',';
  46. }
  47. std::cout << std::endl;
  48. for (auto& o : R) {
  49. std::cout << o << ',';
  50. }
  51. std::cout << std::endl;
  52.  
  53. for (std::size_t i = 1; i < R.size(); i += 2) {
  54. std::cout << R[i]<<',';
  55. }
  56. std::cout << std::endl;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
8,9,11,13,9,13,8,13,6,9,10,6,7,4,14,
8,4,11,6,9,9,8,9,6,13,10,13,7,13,14,
4,6,9,9,13,13,13,