fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. typedef std::vector<int> DType;
  5.  
  6. int Count(DType& vec, std::size_t N, std::size_t idx){
  7. size_t i;
  8. for (i = idx; i < vec.size(); i++)
  9. {
  10. if (vec[i] != N)return i - idx;
  11. }
  12.  
  13. return i - idx;
  14. }
  15. bool Copy(DType& Dest,DType& Src, std::size_t N,std::size_t idx){
  16. for (size_t i = idx; i < Src.size(); i++)
  17. {
  18. if (Src[i] != N)return true;
  19. Dest.push_back(Src[i]);
  20. }
  21.  
  22. return true;;
  23. }
  24. bool Erase(DType& vec, std::size_t N, std::size_t idx){
  25.  
  26. int C = Count(vec, vec[idx], idx);
  27.  
  28. for (size_t i =0; i < vec.size()-idx-C; i++)
  29. {
  30. vec[idx + i] = vec[idx + C + i];
  31. }
  32.  
  33. vec.resize(vec.size() - C);
  34.  
  35. return true;
  36. }
  37.  
  38. std::vector<DType> MakeHoge(DType vec){
  39. std::size_t C = 0;
  40. std::size_t Idx = 0;
  41. DType Res = Res;
  42. std::vector<DType> R;
  43. size_t i = 0;
  44. bool F = false;
  45.  
  46. do{
  47. R.push_back(vec);
  48. F = false;
  49. for (size_t i = 0; i < vec.size(); i++)
  50. {
  51. C = Count(vec, vec[i], i);
  52. if (C >= 4){
  53. Erase(vec, vec[i], i);
  54. F = true;
  55. break;
  56. }
  57. i += C-1;
  58. }
  59.  
  60. } while (F);
  61. //R.pop_back();
  62. return R;
  63. }
  64.  
  65. bool ShowOut(std::vector<DType>& vec){
  66. std::cout << "out:" << std::endl;
  67. for (auto& oo : vec){
  68. for (auto& o : oo) std::cout << o;
  69. if (oo.size() == 0) std::cout << "[None]";
  70. std::cout << std::endl;
  71. }
  72. std::cout << std::endl;
  73. return true;
  74. }
  75. bool ShowIn(const DType& vec){
  76. std::cout << "in:";
  77. for (auto& o : vec) std::cout << o;
  78. std::cout << std::endl;
  79. return true;
  80. }
  81.  
  82. int main(){
  83.  
  84. std::vector<DType> R;
  85.  
  86. auto A{ 1, 1, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 1, 1, 1, 1, 1, 4, 3, 3, 2, 2, 2, 1, 1, };
  87. R = MakeHoge(A);
  88. ShowIn(A);
  89. ShowOut(R);
  90.  
  91. auto B{ 1, 1, 2, 2, 2, 2, 4, 4, 1, 1, 1, 1, 2, 2, 2, 2, };
  92. R = MakeHoge(B);
  93. ShowIn(B);
  94. ShowOut(R);
  95.  
  96. auto C{ 2,1,1,2,2,2,2,1,1,3,3,3,3,1,2, };
  97. R = MakeHoge(C);
  98. ShowIn(C);
  99. ShowOut(R);
  100.  
  101. return 0;
  102. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
in:11233344433331111143322211
out:
11233344433331111143322211
1123334441111143322211
11233344443322211
1123333322211
11222211
1111
[None]

in:1122224411112222
out:
1122224411112222
114411112222
11442222
1144

in:211222211333312
out:
211222211333312
21111333312
2333312
212