#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <cstdint>
#include <random>
typedef std::tuple < std::wstring::value_type, std::uintmax_t> Data;
typedef std::vector<Data> DType;
std::wstring MakeString(std::wstring S, std::size_t C,std::size_t N) {
std::mt19937 mt;
std::uniform_int_distribution<std::size_t> Lid(1, C);
std::uniform_int_distribution<std::size_t> Pid(0, S.size()-1);
std::size_t C1 = Lid(mt);
std::uniform_int_distribution<std::size_t> Nid(1, N);
std::wstring R;
for (std::size_t i = 0; i < C1; i++) {
std::size_t N1 = Nid(mt);
std::size_t P1 = Pid(mt);
for (std::size_t j = 0; j < N1; j++) {
R += S[P1];
}
}
return R;
}
DType MakeHoge(const std::wstring& S) {
std::wstring::value_type Ch=S.front();
std::size_t j = 0;
DType D;
for (std::size_t i = 0; i < S.size();i++) {
j = i;
Ch = S[i];
for (j; j<S.size()&&S[j] == Ch; j++) {};
D.push_back({ Ch,j - i });
i=j-1;
}
return D;
}
bool Show(const DType& D) {
std::wcout.imbue(std::locale("Japanese"));
for (auto& o : D) {
if (std::get<1>(o) > 1) {
//std::wcout <<std::get<0>(o)<< std::get<1>(o);
std::wcout <<'['<< std::get<0>(o)<<':' << std::get<1>(o)<<']';
}
else {
std::wcout <<'['<< std::get<0>(o)<<']';
}
}
std::wcout << std::endl;
return true;
}
int main() {
auto L = std::wcout.imbue(std::locale("Japanese"));
std::wstring S;
DType R;
S = L"あいうえお";
R=MakeHoge(S);
Show(R);
S = L"ああいいうう";
R=MakeHoge(S);
Show(R);
S = MakeString(L"あいうえお",8,7);
std::wcout << S << std::endl;
R=MakeHoge(S);
Show(R);
std::wcout.imbue(L);
return 0;
}