#include <iostream>
#include <vector>
#include <string>
#include <sstream>
typedef std::pair<char, std::size_t> CS;
typedef std::vector<CS> VecCS;
std::string StringCast(int N){
std::stringstream ss;
ss << N;
return ss.str();
}
VecCS CountChar(std::string str){
CS P = std::make_pair(str[0], 0);
VecCS vec;
for (std::size_t i = 0; i < str.size(); i++){
if (P.first != str[i]){
vec.push_back(P);
P = std::make_pair(str[i], 1);
}
else{
P.second++;
}
}
vec.push_back(P);
return vec;
}
std::string ToString(VecCS vec){
std::string str;
for (auto& o: vec){
str += StringCast(o.second);
str += o.first;
}
return str;
}
int main(){
std::string str = "1";
std::size_t N = 10;
std::size_t i=0;
char *Answer[] = { "1", "11", "21", "1211", "111221", "312211", "13112221", "1113213211", "31131211131221", "13211311123113112211", "11131221133112132113212221" };
for (i = 0; i < N; i++){
std::cout << i << ":" << str << ' ' << ((str == Answer[i]) ? " " : "Invalid!!") << std::endl;
auto ret = CountChar(str);
str = ToString(ret);
}
std::cout << i << ":" << str << ' ' << ((str == Answer[i]) ? " " : "Invalid!!") << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KCnR5cGVkZWYgc3RkOjpwYWlyPGNoYXIsIHN0ZDo6c2l6ZV90PiBDUzsKdHlwZWRlZiBzdGQ6OnZlY3RvcjxDUz4gVmVjQ1M7CgpzdGQ6OnN0cmluZyBTdHJpbmdDYXN0KGludCBOKXsKCXN0ZDo6c3RyaW5nc3RyZWFtIHNzOwoKCXNzIDw8IE47CglyZXR1cm4gc3Muc3RyKCk7Cn0KClZlY0NTIENvdW50Q2hhcihzdGQ6OnN0cmluZyBzdHIpewoJQ1MgUCA9IHN0ZDo6bWFrZV9wYWlyKHN0clswXSwgMCk7CglWZWNDUyB2ZWM7CgoJZm9yIChzdGQ6OnNpemVfdCBpID0gMDsgaSA8IHN0ci5zaXplKCk7IGkrKyl7C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