import sys
while True:
a=[]
res=" "
a=sys.stdin.read().split()
if len(a):
row=int(a[0])
col=int(a[1])
a.pop(0)
for i in range(0,col):
for j in range(i,(i+col*(row-1))+1,col):
res+=a[j]+" "
res=res[:1]
res+="\n"
print(res)
else:
break
import sys
while True:
a=[]
res=" "
a=sys.stdin.read().split()
if len(a):
row=int(a[0])
col=int(a[1])
a.pop(0)
for i in range(0,col):
for j in range(i,(i+col*(row-1))+1,col):
res+=a[j]+" "
res=res[:1]
res+="\n"
print(res)
else:
break
每組測資可以用
for line in sys.stdin: [row, col] = [int(x) for x in line.strip().split()] # TODO
來開頭,會單純一點。
把 a
做成 nested list,能直接取 a[r][c]
,會比較方便。