python求助!!实在找不出错哪了
查看原帖
python求助!!实在找不出错哪了
867220
Xi3414954826楼主2024/2/28 14:56

求助python,找不到错误点,就20分

lst1 = []
lst2=[]
lst3=[]
a=0
b=0
while True:
    try:
        line = input()
        if not line:
            break
        lst1.append(line)
    except EOFError:
        break
n=len(lst1)
lst3.append(n)
for i in lst1:
    for j in range(len(i)):
        lst2.append(i[j])
# print(lst2)
c=lst2.index('0')
for i in range(c,len(lst2)):
    if lst2[i] == '0':
        if b!=0:
            lst3.append(b)
            b=0
        a+=1
    elif lst2[i]=='1':
        if a!=0:
            lst3.append(a)
            a=0
        b+=1
if a != 0:
    lst3.append(a)
elif b != 0:
    lst3.append(b)
print(' '.join(map(str,lst3)))
2024/2/28 14:56
加载中...