fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <vector>
  4. #include <string>
  5. #include <cstdint>
  6.  
  7. typedef std::vector<std::string> SType;
  8. typedef std::tuple<char, std::uint64_t> DType;
  9. typedef std::vector<DType> SDType;
  10. typedef std::vector<SDType> RType;
  11.  
  12. SDType Comp(std::string& S){
  13. char C = S[0];
  14. std::uint64_t N=0;
  15. SDType R;
  16.  
  17. for (auto& o : S){
  18. if (C != o){
  19. R.push_back(std::make_tuple(C, N));
  20. C = o;
  21. N = 0;
  22. }
  23. N++;
  24. }
  25. R.push_back(std::make_tuple(C, N));
  26.  
  27. return R;
  28. }
  29.  
  30. RType MakeHoge(SType& S){
  31. RType R;
  32. for (auto&o : S){
  33. R.push_back(Comp(o));
  34. }
  35.  
  36. return R;
  37. }
  38.  
  39. bool Show(SType& S,RType& R){
  40. char C='\0';
  41. std::uint64_t N=0;
  42. for (auto& o : S){
  43. std::cout <<o<<std::endl;
  44. }
  45. for (auto& oo : R){
  46. for (auto& o : oo){
  47. std::tie(C, N) = o;
  48. std::cout << C << N;
  49. }
  50. std::cout << std::endl;
  51. }
  52. std::cout << std::endl;
  53. return true;
  54. }
  55.  
  56. int main(){
  57. SType S;
  58. RType R;
  59.  
  60. SType S1{ "aabbcc" };
  61. S = S1;
  62. R = MakeHoge(S);
  63. Show(S,R);
  64.  
  65. SType S2{ "abcde","aabbb" };
  66. S = S2;
  67. R = MakeHoge(S);
  68. Show(S,R);
  69.  
  70. SType S3{ "aaa","bbb","ccc" };
  71. S = S3;
  72. R = MakeHoge(S);
  73. Show(S,R);
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
aabbcc
a2b2c2

abcde
aabbb
a1b1c1d1e1
a2b3

aaa
bbb
ccc
a3
b3
c3