fuukoukanro @ 2023-12-23 08:50:10
我用python做的,代码如下,来个大佬救救孩子吧TAT
b=input("")
N=len(b)
a=[]
num=[]
for i in range(0,N):
a.append(int(b[i]))
num.append(N)
n=0
flag=0
for i in range(0,N):
if(a[i]==0 and flag==0):
n+=1
elif(a[i]==1 and flag==0):
num.append(n)
flag=1
n=1
elif(a[i]==1 and flag==1):
n+=1
elif(a[i]==0 and flag==1):
num.append(n)
n=1
flag=0
del a[:]
for i in range(0,N-1):
b=input("")
for i in range(0,N):
a.append(int(b[i]))
if(a[i]==0 and flag==0):
n+=1
elif(a[i]==1 and flag==0):
num.append(n)
flag=1
n=1
elif(a[i]==1 and flag==1):
n+=1
elif(a[i]==0 and flag==1):
num.append(n)
n=1
flag=0
del a[:]
num.append(n)
for i in range(0,len(num)):
print(num[i],"",end="")
by Winds_Land @ 2024-01-29 16:40:30
# 由输入为N*N矩阵,可以从第一行输入获取N
lst = list(map(int, input()))
n = len(lst)
for _ in range(n-1):
lst.extend(list(map(int, input())))
# ans是用于输出答案的数组,ans[0]为N,后面为压缩数字;cnt用于记录当前数字出现的次数
ans = [n]
cnt = 1
# 若第一个数字为1,则向ans添加0
if lst[0]:
ans.append(0)
for i in range(1,n*n):
if lst[i]==lst[i-1]:
cnt += 1
else:
ans.append(cnt)
cnt = 1
ans.append(cnt)
for i in ans:
print(i,end=' ')
参考一下