sys读入的时候会把换行符也读进去
1028
没想到办法怎么在不产生列表的前提下直接进行未知数量的切片存取,用re可能可以。
import sys
n = int(input())
low = 100
high = 0
lowotp = ''
highotp = ''
for i in range(n):
s = sys.stdin.readline()#readline的字符串后面跟了一个/n
sl = s.split(' ')#先用split做吧
if int(sl[-1])<low:
low = int(sl[-1])
lowotp = s
if int(sl[-1])>high:
high = int(sl[-1])
highotp = s
h1 = highotp.split(' ')
l1 = lowotp.split(' ')
print(' '.join(h1[0:2]))
print(' '.join(l1[0:2]))
本文介绍如何使用Python从标准输入读取一行数据,通过`sys.stdin.readline()`处理换行符,并利用split()函数实现根据输入数值范围进行未知数量切片。重点在于不创建额外列表,仅针对`low`和`high`边界进行操作。
&spm=1001.2101.3001.5002&articleId=120090948&d=1&t=3&u=e2cc0b4e9e2c4281aa7d39f8b8c2bbad)

被折叠的 条评论
为什么被折叠?



