Python在竞争性编码中获得测试用例的输入
如何为列表中有N个值的T测试用例获取输入 其中T是测试用例的数量,N是列表中输入的长度Python在竞争性编码中获得测试用例的输入,python,python-3.x,input,testcase,Python,Python 3.x,Input,Testcase,如何为列表中有N个值的T测试用例获取输入 其中T是测试用例的数量,N是列表中输入的长度 3 3 2 2 2 3 1 2 3 4 2 3 4 5 我想拿出清单来处理它们,比如: [2, 2, 2] [1, 2, 3] [2, 3, 4, 5] 请注意,此脚本不会对输入进行任何验证,并且测试用例的长度(即l)实际上不是必需的 T = int(input()) testCases = [] for i in range(T): l = int(input()) testCase
3
3
2 2 2
3
1 2 3
4
2 3 4 5
我想拿出清单来处理它们,比如:
[2, 2, 2]
[1, 2, 3]
[2, 3, 4, 5]
请注意,此脚本不会对输入进行任何验证,并且测试用例的长度(即
l
)实际上不是必需的
T = int(input())
testCases = []
for i in range(T):
l = int(input())
testCase = [int(x) for x in input().split(" ")]
testCases.append(testCase)
print(testCases)
Python
kases = int(input())
for kase in range(kases):
N = int(input())
result = 1
for i in range(1, N + 1):
result = result * i
print (result)
但是,我不知道如何回答另一部分。您可以简单地使用string的
split
方法,通过'
(空格)和map
函数将字符串输入值转换为整数来分隔元素
for _ in range(int(input())):
input() # gets length of list, but doesn't store it
input_list = list(map(int, input().split()))
print(input_list)
for _ in range(int(input())):
input() # gets length of list, but doesn't store it
input_list = list(map(int, input().split()))
print(input_list)