0
点赞
收藏
分享

微信扫一扫

1140 Look-and-say Sequence (20 分) (字符串 模拟

code_balance 2022-02-23 阅读 45

添加链接描述

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string d;
	cin>>d>>n;
	for(int i=1;i<n;i++){
		string p;
		char ch=d[0];
		int tot=0;
		for(int j=0;j<d.size();j++){
			if(d[j]==ch){
				tot++;
			}
			else {
				p+=ch;
				p+=tot+'0';
				tot=1;
				ch=d[j];
			}
		}
		if(tot)p+=ch,p+=tot+'0';
		d=p;
	}
	cout<<d<<endl;

	return 0;
}
举报

相关推荐

0 条评论