fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <tuple>
  5. #include <cstdint>
  6. #include <random>
  7.  
  8. typedef std::tuple < std::wstring::value_type, std::uintmax_t> Data;
  9. typedef std::vector<Data> DType;
  10.  
  11. std::wstring MakeString(std::wstring S, std::size_t C,std::size_t N) {
  12. std::mt19937 mt;
  13. std::uniform_int_distribution<std::size_t> Lid(1, C);
  14. std::uniform_int_distribution<std::size_t> Pid(0, S.size()-1);
  15. std::size_t C1 = Lid(mt);
  16. std::uniform_int_distribution<std::size_t> Nid(1, N);
  17.  
  18. std::wstring R;
  19.  
  20. for (std::size_t i = 0; i < C1; i++) {
  21. std::size_t N1 = Nid(mt);
  22. std::size_t P1 = Pid(mt);
  23. for (std::size_t j = 0; j < N1; j++) {
  24. R += S[P1];
  25. }
  26. }
  27. return R;
  28. }
  29.  
  30. DType MakeHoge(const std::wstring& S) {
  31. std::wstring::value_type Ch=S.front();
  32. std::size_t j = 0;
  33. DType D;
  34.  
  35. for (std::size_t i = 0; i < S.size();i++) {
  36. j = i;
  37. Ch = S[i];
  38. for (j; j<S.size()&&S[j] == Ch; j++) {};
  39. D.push_back({ Ch,j - i });
  40. i=j-1;
  41. }
  42.  
  43. return D;
  44. }
  45.  
  46. bool Show(const DType& D) {
  47. std::wcout.imbue(std::locale("Japanese"));
  48. for (auto& o : D) {
  49. if (std::get<1>(o) > 1) {
  50. //std::wcout <<std::get<0>(o)<< std::get<1>(o);
  51. std::wcout <<'['<< std::get<0>(o)<<':' << std::get<1>(o)<<']';
  52. }
  53. else {
  54. std::wcout <<'['<< std::get<0>(o)<<']';
  55. }
  56. }
  57. std::wcout << std::endl;
  58. return true;
  59. }
  60.  
  61. int main() {
  62. auto L = std::wcout.imbue(std::locale("Japanese"));
  63. std::wstring S;
  64. DType R;
  65.  
  66. S = L"あいうえお";
  67. R=MakeHoge(S);
  68. Show(R);
  69.  
  70. S = L"ああいいうう";
  71. R=MakeHoge(S);
  72. Show(R);
  73.  
  74. S = MakeString(L"あいうえお",8,7);
  75. std::wcout << S << std::endl;
  76. R=MakeHoge(S);
  77. Show(R);
  78.  
  79. std::wcout.imbue(L);
  80. return 0;
  81.  
  82. }
Runtime error #stdin #stdout #stderr 0s 4280KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid