一组输出两行,总共有多组,需要处理一下。
import sys
odd=1
ls=[]
for line in sys.stdin:
l=line.strip()
if odd%2==1:
ls.append(line)
else:
n=int(line)
print(ls[0][:n])
ls=[]
odd+=1用try except,直接一次读2行,更好。
import sys
odd=1
ls=[]
while:
try:
s=input()
n=int(input()
print(ls[:n])
ls=[]
except:
break


京公网安备 11010502036488号