题目
题意分析:
第一项 为d;
第二项 是对第一项的描述,描述形式为 第一项有1个d,所以第二项为 d1;
第三项 是对第二项的描述,描述形式为 第二项有1个d,1个1,所以第三项为d1 11;
第四项 是对第三项的描述,描述形式为 第三项有1个d,3个1,所以第四项为d1 13;
第五项 是对第四项的描述,描述形式为 第四项有1个d,2个1,1个3,所以第五项为 d1 12 31;
第六项 是对第五项的描述,描述形式为 第五项有1个d,2个1, 1个2,1个3,1个1,所以第六项 为 d1 12 21 31 11;
依次类推。
1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 int n; 6 string d; 7 cin>>d>>n; 8 for(int i = 1; i < n;++i) { 9 string temp; 10 for(int i = 0; i < d.size(); ++i) { 11 int cnt = 1; 12 while(i+1 < d.size() && d[i] == d[i+1]) {//统计连续相同数字的个数 13 cnt++; 14 i++; 15 } 16 temp += d[i]; 17 temp += cnt +‘0‘; 18 } 19 d = temp; 20 } 21 printf("%s\n",d.c_str()); 22 return 0; 23 }
原文:https://www.cnblogs.com/keep23456/p/12365241.html