#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char c,temp,now;
int i,j,len,n,cishu,sum;
string first,over;
cin>>c;
now=getchar();
getline(cin,first);
len=first.length();
if(c=='C')
{
cishu=1;
if(len==1)
{
over=first;
}
for(i=0;i<len-1;i++)
{
if(first[i]==first[i+1])
{
cishu=cishu+1;
temp=first[i];
if(i==len-2)//最后一个字母和倒数第二个字母相同
{
cout<<cishu;
cout<<temp;
}
}
else
{
temp=first[i];//当前字符
if(cishu>1)//出现次数大于1则加上数字
{
cout<<cishu;//考虑了次数大于9的情况,但是因为是用字符串处理的,所以很难输出,因此将其改为单个字符输出,次数则直接输出int
}
cout<<temp;//输出字符串加上当前字符
if(i==len-2)cout<<first[len-1];//最后一个字符和最后两个字符不同情况
cishu=1;
}
}
}
else if(c=='D')
{
sum=0;
for(i=0;i<len;i++)
{
if(first[i]>='0'&&first[i]<='9')
{
if(first[i+1]>='0'&&first[i+1]<='9')
{
n=first[i]-'0';
sum=sum*10+n;
//i++;
}
else
{ n=first[i]-'0';
sum=sum*10+n;
//cout<<sum<<endl;
for(j=0;j<sum;j++)
{
over=over+first[i+1];
}
sum=0;
i++;
}
}
else
{
over=over+first[i];
sum=0;
}
}
}
cout<<over<<endl;
}
虽然写的很丑,但是还是要记录一下自己。。
以后复习的时候注意下吧