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. DType EvenSort(DType D) {
  37.  
  38. for (std::size_t i = 0; i < D.size(); i++) {
  39. if (i % 2 == 1) { continue; }
  40. for (std::size_t j = i+1; j < D.size(); j++) {
  41. if (j % 2 == 1) { continue; }
  42.  
  43. if (D[i]/2 > D[j]/2) {
  44. std::swap(D[i], D[j]);
  45. }
  46. }
  47. }
  48. return D;
  49. }
  50. int main() {
  51. DType D;
  52. DType O;
  53. DType E;
  54. D = MakeVector(15);
  55.  
  56. O = OddSort(D);
  57. E = EvenSort(O);
  58. for (auto& o : D) {
  59. std::cout << o << ',';
  60. }
  61. std::cout << std::endl;
  62. for (auto& o : E) {
  63. std::cout << o << ',';
  64. }
  65. std::cout << std::endl;
  66.  
  67. for (std::size_t i = 1; i < E.size(); i += 2) {
  68. std::cout << E[i]<<',';
  69. }
  70. std::cout << std::endl;
  71. for (std::size_t i = 0; i < E.size(); i += 2) {
  72. std::cout << E[i]<<',';
  73. }
  74. std::cout << std::endl;
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 4484KB
stdin
Standard input is empty
stdout
8,9,11,13,9,13,8,13,6,9,10,6,7,4,14,
6,4,7,6,8,9,8,9,9,13,10,13,11,13,14,
4,6,9,9,13,13,13,
6,7,8,8,9,10,11,14,