one_s = input()
my_num = []
i= 0
all_num = [str(k) for k in list(range(10))]
while i<len(one_s):
one_num = ‘0’
one_ss = ‘’
if one_s[i] in all_num:
while i<len(one_s):
if one_s[i] in all_num:
one_num += one_s[i]
i += 1
if i==len(one_s):
my_num.append(int(one_num))
else:
my_num.append(int(one_num))
break
else:
while i<len(one_s):
if one_s[i] not in all_num:
one_ss += one_s[i]
i += 1
if i==len(one_s):
my_num.append(one_ss)
else:
my_num.append(one_ss)
break
p_ss = ‘’
j=0
my_num_len = len(my_num)
for j in range(1,my_num_len):
if (j+1)%2==0:
for k in range(my_num[j]):
p_ss += my_num[j-1]
else:
if j == my_num_len-1:
p_ss += my_num[j]
print(p_ss)
C语言最终通过的代码:(我原先是把结果存在一个数组里面最后再输出,但第七个测试一直超时,于是我改为边判断边输出就通过了,有点奇怪)
include
include
int is_number(char str)
{
if(str >= ‘0’ && str <= ‘9’)
{
return str-‘0’;
}
return -1;
}
int main()
{
char p[10005],temp[10005]={0};
scanf(“%s”,p);
int fir=0,end=0,len=strlen(p),i,num=0,r;
if(is_number(p[len-1])==-1){p[len]=‘1’;p[len+1]=’\0’;len+=1;}
while(end<len)
{
if(is_number(p[end])==-1) end++;
else
{
for(i=end;is_number(p[i])!=-1;i++)
{
num*=10;
num+=is_number(p[i]);
}
r=i;
for(i=fir;i<end;i++)
{
temp[i-fir]=p[i];
}
temp[i-fir]=’\0’;
for(i=0;i<num;i++)
{
printf(“%s”,temp);//原先是通过strcat函数连接起来,等最大的while循环结束后再输出,现改为直接printf
}
end=r;
fir=end;
num=0;
}
}
return 0;
}
one_s = input()
my_num = []
i= 0
all_num = [str(k) for k in list(range(10))]
while i<len(one_s):
one_num = ‘0’
one_ss = ‘’
if one_s[i] in all_num:
while i<len(one_s):
if one_s[i] in all_num:
one_num += one_s[i]
i += 1
if i==len(one_s):
my_num.append(int(one_num))
else:
my_num.append(int(one_num))
break
else:
while i<len(one_s):
if one_s[i] not in all_num:
one_ss += one_s[i]
i += 1
if i==len(one_s):
my_num.append(one_ss)
else:
my_num.append(one_ss)
break
p_ss = ‘’
j=0
my_num_len = len(my_num)
for j in range(1,my_num_len):
if (j+1)%2==0:
for k in range(my_num[j]):
p_ss += my_num[j-1]
else:
if j == my_num_len-1:
p_ss += my_num[j]
print(p_ss)