AcWing 3187. 奇怪的数列(字符串的操作)
原题链接
简单
作者:
xrzscxy
,
2021-04-02 11:10:30
,
所有人可见
,
阅读 621
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 30;
string s;
int n;
int main(){
cin >> s;
cin >> n;
for(int m = 0;m < n;m++){
string nexts = "";
for(int i = 0;i < s.length();){
int t = s[i]-'0';
int k = 1;//计数
for(int j = i+1;j < s.length();j++){
if(s[i] == s[j]){
k++;
}
else{
break;
}
}
nexts += (k+'0');
nexts += (t+'0');
//i += k;
i += k;
}
s = nexts;
}
cout << s << endl;
return 0;
}