fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <cstdint>
  5. #include <algorithm>
  6.  
  7. typedef std::vector<std::uintmax_t> DType;
  8.  
  9. DType MakeVector(const std::size_t& N,const unsigned int& RS=0) {
  10. std::minstd_rand mr(RS);
  11.  
  12. DType R(N);
  13.  
  14. for (auto& o : R) {
  15. o = mr();
  16. }
  17.  
  18. std::shuffle(R.begin(), R.end(), mr);
  19.  
  20. return R;
  21. }
  22.  
  23. DType StalinSort(const DType& D) {
  24.  
  25. DType R;
  26.  
  27. R.push_back(D.front());
  28.  
  29. for (std::size_t i = 1; i < D.size(); i++) {
  30. if (D[i] > D[i - 1]) {
  31. R.push_back(D[i]);
  32. }
  33. }
  34.  
  35. return R;
  36. }
  37.  
  38. int main() {
  39. DType D = MakeVector(32);
  40. DType R = D;
  41. while (!std::is_sorted(R.begin(), R.end())) {// ...o(N)????
  42. R = StalinSort(R);
  43. }
  44.  
  45. for (auto& o : D) {
  46. std::cout << o << ',';
  47.  
  48. }
  49. std::cout << std::endl;
  50. std::cout << std::endl;
  51. for (auto& o : R) {
  52. std::cout << o << ',';
  53.  
  54. }
  55. std::cout << std::endl;
  56.  
  57. return 0;
  58.  
  59. }
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
182605794,1271135913,631416347,48271,2075782095,2010567813,2136927794,1250328747,2064876628,1738531149,1402304087,1203428207,1936030137,1914720637,2078669041,564586691,1105902161,1098894339,407355683,1931656580,353718330,638022372,854716505,1882556969,1842513780,1559527823,1291394886,914937185,1596680831,1947433875,890442452,192302371,

182605794,1271135913,2075782095,2136927794,