题目描述:输入第一行是每次读取的固定长度,第2-n行是要合并的数组;输出合并后的数组。
eg:
#input:
#3
#2,5,6,7,9,5,7
#1,7,4,3,4
#output:
#2,5,6,1,7,4,7,9,5,3,4,7
python实现:
#input:
#3
#2,5,6,7,9,5,7
#1,7,4,3,4
#output:
#2,5,6,1,7,4,7,9,5,3,4,7
#
#coding=utf-8
import sys
array_all=[]
array=[]
num=int(sys.stdin.readline().strip())
while True:
line=sys.stdin.readline().strip()
if line=="":
break
line=line.split(',')
line=list(map(int,line))
array_all.append(line)
print(num)
print(array_all)
row=len(array_all)
print(row)
while True:
count=0
for i in range(row):
n=len(array_all[i])
if n==0:
count+=1
continue
elif n<=num:
for j in array_all[i]:
array.append(j)
#array.append(array_all[i][:])
array_all[i]=[]
elif n>num:
for k in array_all[i][:num]:
array.append(k)
#array.append(array_all[i][:num])
array_all[i]=array_all[i][num:]
if(count==row):
break
print(array)
print(",".join(list(map(str,array))))