#include <iostream>
#include <vector>
typedef std::vector<int> DType;
int Count(DType& vec, std::size_t N, std::size_t idx){
size_t i;
for (i = idx; i < vec.size(); i++)
{
if (vec[i] != N)return i - idx;
}
return i - idx;
}
bool Copy(DType& Dest,DType& Src, std::size_t N,std::size_t idx){
for (size_t i = idx; i < Src.size(); i++)
{
if (Src[i] != N)return true;
Dest.push_back(Src[i]);
}
return true;;
}
bool Erase(DType& vec, std::size_t N, std::size_t idx){
int C = Count(vec, vec[idx], idx);
for (size_t i =0; i < vec.size()-idx-C; i++)
{
vec[idx + i] = vec[idx + C + i];
}
vec.resize(vec.size() - C);
return true;
}
std::vector<DType> MakeHoge(DType vec){
std::size_t C = 0;
std::size_t Idx = 0;
DType Res = Res;
std::vector<DType> R;
size_t i = 0;
bool F = false;
do{
R.push_back(vec);
F = false;
for (size_t i = 0; i < vec.size(); i++)
{
C = Count(vec, vec[i], i);
if (C >= 4){
Erase(vec, vec[i], i);
F = true;
break;
}
i += C-1;
}
} while (F);
//R.pop_back();
return R;
}
bool ShowOut(std::vector<DType>& vec){
std::cout << "out:" << std::endl;
for (auto& oo : vec){
for (auto& o : oo) std::cout << o;
if (oo.size() == 0) std::cout << "[None]";
std::cout << std::endl;
}
std::cout << std::endl;
return true;
}
bool ShowIn(const DType& vec){
std::cout << "in:";
for (auto& o : vec) std::cout << o;
std::cout << std::endl;
return true;
}
int main(){
std::vector<DType> R;
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, };
R = MakeHoge(A);
ShowIn(A);
ShowOut(R);
auto B{ 1, 1, 2, 2, 2, 2, 4, 4, 1, 1, 1, 1, 2, 2, 2, 2, };
R = MakeHoge(B);
ShowIn(B);
ShowOut(R);
auto C{ 2,1,1,2,2,2,2,1,1,3,3,3,3,1,2, };
R = MakeHoge(C);
ShowIn(C);
ShowOut(R);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtP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