求助:python,60分,不过的全RE

P1320 压缩技术(续集版)

Dahailt @ 2022-11-10 18:58:29

测试点 #2 #8 #9 #10 得了RE,剩下的过了,60分。

问题代码如下:

inputline = input().strip()
n = len(inputline)
for i in range(n-1):
    inputline += input().strip()

end_i = len(inputline)
inputline += "end"
def zipcode(i,count):
    if i>=end_i:
        return
    if inputline[i]==inputline[i+1]:
        return zipcode(i+1,count+1)
    print(count,end=" ")
    return zipcode(i+1,1)
print(n, end=" ")
if inputline[0]=='1':
    print('0', end=" ")
zipcode(0,1)

这是为什么呀?


by Dahailt @ 2022-11-11 20:14:09

把函数改为循环就过了,还是不明白之前为什么 RE

inputline = input().strip()
n = len(inputline)
for i in range(n-1):
    inputline += input().strip()

end_i = len(inputline)
inputline += "end"
print(n, end=" ")
if inputline[0]=='1':
    print('0', end=" ")
i,count = 0,1
while i<end_i:
    if inputline[i]==inputline[i+1]:
        i += 1
        count += 1
        continue
    print(count,end=" ")
    i += 1
    count = 1

有人能给我解惑吗?


|