今天在做PTA上的1066 图像过滤这道题时发现,使用*来对列表拆包输出时会超时,而改用join()函数时不会超时。
使用*拆包代码(会超时)
M,N,A,B,rep = map(int,input().split())
res = []
for i in range(M):
temp = ['{:0>3d}'.format(rep) if A <= j <= B else '{:0>3d}'.format(j) for j in list(map(int,input().split()))]
print(*temp)
改用join()代码(不超时)
M,N,A,B,rep = map(int,input().split())
res = []
for i in range(M):
temp = ['{:0>3d}'.format(rep) if A <= j <= B else '{:0>3d}'.format(j) for j in list(map(int,input().split()))]
print(' '.join(temp))