一指流沙 @ 2022-03-20 13:23:25
代码如下:
lists = []
l, y = 0, 0
temp = input()
lists.append(len(temp))
for i in range(1, lists[0]):
temp += input()
if temp[0] != '0': # 若第一个为1则直接添加0
lists.append(0)
for i in list(temp):
if i == '0':
l += 1
else:
y += 1
if i == '0' and y > 0:
lists.append(y)
y = 0
if i == '1' and l > 0:
lists.append(l)
l = 0
lists.append(l) if l > 0 else lists.append(y)
print(' '.join(list(map(str, lists))), end=' ')