1140 Look-and-say Sequence (20 分)【难度: 一般 / 知识点: 模拟】

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805344490864640

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    
    
    string s; cin>>s;
    int n; cin>>n;
    for(int i=2;i<=n;i++)
    {
    
    
        string temp;
        for(int j=0;j<s.size();j++)
        {
    
    
            int z=j;
            while(z+1<s.size()&&s[z]==s[z+1]) z++;
            temp+=s[j]+to_string(z-j+1);
            j=z;
        }
        s=temp;
    }
    cout<<s;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46527915/article/details/121576278
今日推荐