啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
这道题对于一个蒟蒻来说是多么炸裂!
我的思路是这样的:
循环遍历每一轮字符串
用一个队列来保存每个数字出现多少次
最后利用队列来将字符串拼接
#include<bits/stdc++.h>
using namespace std;
string s;
long long n,cnt=0;
struct aa{
long long count;
char num;
};
queue<aa> q;
char x;
int main()
{
cin>>s;
cin>>n;
for(int i=1;i<=n;i++)
{
x=s[0];
cnt=0;
for(int j=0;j<s.size();j++)
{
if(s[j]==x)
{
cnt++;
}
if(s[j]!=x)
{
q.push({cnt,x});
cnt=1;
x=s[j];
}
}
q.push({cnt,x});
s="";
while(!q.empty())
{
string ncount=to_string(q.front().count);
char nnum=q.front().num;
q.pop();
s=s+ncount;
s=s+string(1,nnum);
}
}
cout<<s<<endl;
return 0;
}
多么新奇的想法