python3的OJ输入

1、输入整数

1
2
3
case = int(input().strip())
while case:
case -= 1

2、 输入浮点数

1
test = float(input().strip())

3、字符串

1
test = input().strip()

4、 输入 1 2 3 4 5

1
nums = list(map(int, input().strip().split()))

5、输入 1.0 2.0 3.0 4.0

1
nums = list(map(float, input().strip().split()))

6、输入 a b c d e

1
test = list(input().strip().split())

7、创建二维数组

1
test = [[0 for i in range(col)] for j in range(row)]

8、未知多少输入行

1
2
3
4
5
6
7
8
9
10
11
12
while True:
line = sys.stdin.readline()
if not line:
break
nums = []
i = -1
for str_x in line.strip().split(' '):
i += 1
if i == 0:
len_nuns = int(str_x)
continue
nums.append(int(str_x))

9、满足条件一的情况下对条件二排序

1
2
3
a = [[2, 3], [4, 1], [2, 8], [2, 1], [3, 4]]
a.sort(key=lambda x: (x[1], -x[0]))
print(a)

python3的OJ输入
https://zhangfuli.github.io/2019/10/13/python3的OJ输入/
作者
张富利
发布于
2019年10月13日
许可协议