其他分享
首页 > 其他分享> > 1281: [蓝桥杯2015决赛]奇怪的数列 【中 / 字符串】

1281: [蓝桥杯2015决赛]奇怪的数列 【中 / 字符串】

作者:互联网

在这里插入图片描述
http://oj.ecustacm.cn/problem.php?id=1281

#include<cstring>
#include<string>
#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
	string a;
	int n;
	cin>>a>>n;
	for(int i=1;i<=n;i++)
	{
		string b;
		int k=1;//统计相同字符的个数
		for(int j=0;j<a.size();j++)
		{
			if(a[j]==a[j+1])
			{
				k++;
			}
			else
			{
				b=b+to_string(k)+a[j];  //相邻两个不相同,将上面统计的结果记录到b里
				k=1;
			}
		}
		a=b;//更新新的a
	}
	cout<<a<<endl; 
	return 0;
}

标签:1281,string,相同,int,蓝桥,2015,include
来源: https://blog.csdn.net/bettle_king/article/details/115483663