题目:
题解:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int x, n; //数字d,第n项
cin >> x >> n;
string t = to_string(x); //记录每一项
int count = 1; //记录每个变量的个数
n--;
string temp; //记录每一轮的字符串
while (n--)
{
for (int i = 0; i <(int)t.size(); i++)
{
if (t[i] == t[i + 1]) //相同则个数加一
{
count++;
}
else //个数计算完毕,则记录新字符串
{
temp += (t[i] + to_string(count));
count = 1; //恢复初始状态
continue;
}
}
t = temp; //改变源字符串
temp.clear(); //清空临时字符串变量
}
cout << t;
return 0;
}