fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::size_t NextList(std::vector<int> vec,std::size_t Start=0){
  5. std::size_t i = Start;
  6.  
  7. for (i=Start; i < vec.size()-1; i++){
  8. if (vec[i] > vec[i + 1])break;
  9. }
  10.  
  11. return i;
  12.  
  13. }
  14.  
  15.  
  16. std::vector < std::vector<int>> ToList(const std::vector<int>& vec){
  17. std::vector<std::vector<int>> vecvec;
  18. std::size_t S = 0;
  19. std::size_t E = 0;
  20.  
  21. while (E < vec.size()){
  22. E = NextList(vec,S);
  23. E++;
  24. vecvec.push_back(std::vector<int>(vec.begin() + S, vec.begin() + E));
  25. S = E;
  26. }
  27.  
  28. return vecvec;
  29. }
  30.  
  31. bool Show(std::vector<int>& vec, std::vector < std::vector<int>> & vecvec){
  32. std::cout << '[';
  33. for (auto& o : vec) std::cout << o << ',';
  34. std::cout << ']';
  35.  
  36. std::cout << " => ";
  37.  
  38. std::cout << '[';
  39. for (auto& oo : vecvec){
  40. std::cout << '[';
  41. for (auto& o : oo) std::cout << o << ',';
  42. std::cout << ']';
  43. }
  44. std::cout << ']' << std::endl;
  45.  
  46. return true;
  47.  
  48. }
  49. int main(){
  50.  
  51. std::vector<int> vec;
  52. std::vector<std::vector<int>> vecvec;
  53.  
  54. vec = { 8, 3, 4, 9, 9, 10, 6, 1, 4, 3 };// = > [[8], [3, 4, 9, 9, 10], [6], [1, 4], [3]]
  55. vecvec= ToList(vec);
  56. Show(vec,vecvec);
  57. vec = { 1, 3, 3, 4, 4, 6, 8, 9, 9, 10 };// = > [[1, 3, 3, 4, 4, 6, 8, 9, 9, 10]]
  58. vecvec= ToList(vec);
  59. Show(vec,vecvec);
  60. vec = { 10, 9, 9, 8, 6, 4, 4, 3, 3, 1 };/// = > [[10], [9, 9], [8], [6], [4, 4], [3, 3], [1]]
  61. vecvec= ToList(vec);
  62. Show(vec,vecvec);
  63. vec = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };// = > [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
  64. vecvec= ToList(vec);
  65. Show(vec,vecvec);
  66. vec = {};// = > []
  67. vecvec= ToList(vec);
  68. Show(vec,vecvec);
  69. vec = { 1 };// = > [[1]]
  70. vecvec= ToList(vec);
  71. Show(vec,vecvec);
  72.  
  73. return 0;
  74.  
  75. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
[8,3,4,9,9,10,6,1,4,3,] => [[8,][3,4,9,9,10,][6,][1,4,][3,]]
[1,3,3,4,4,6,8,9,9,10,] => [[1,3,3,4,4,6,8,9,9,10,]]
[10,9,9,8,6,4,4,3,3,1,] => [[10,][9,9,][8,][6,][4,4,][3,3,][1,]]
[1,1,1,1,1,1,1,1,1,1,] => [[1,1,1,1,1,1,1,1,1,1,]]
[] => []
[1,] => [[1,]]