PTA(Basic Level) 1084:外观数列(C语言实现)
#include <stdio.h>
#include <string.h>
int main()
{
int d,n,i,j,k,count,len;
char s[100000]="",t[100000]="";//数组开大一点
scanf("%d%d",&d,&n);
s[0]=d+'0';
for(i=0; i<n-1; i++)
{
count=1,len=strlen(s),k=0;
for(j=1; j<=len; j++)//最后的结果也要存入
{
if(s[j] == s[j-1])
count++;
else
{
t[k++]=s[j-1];
t[k++]=count+'0';
count=1;
}
}
strcpy(s,t);
}
printf("%s",s);
return 0;
}