Google 启动 A 轮 Python 中的运行时错误
Runtime Error in Google Kick Start Round A for Python
由于未知原因,系统说我的代码有错误,而我的编辑器运行正常。知道为什么我的代码不起作用吗? (为了更清楚,我正在 kickstart 编辑器中根据给定的输入测试我的程序(而不是提交)。)
case = int(input())
for i in range(case):
price = 0
amount = 0
num, budget = input().split()
houses = sorted(input().split(), key=int)
for house in houses:
price += int(house)
if price > int(budget):
break
amount += 1
print(f'Case #{i+1}: {amount}')
我给测试的输入
Input
3
4 100
20 90 40 90
4 50
30 30 10 10
3 300
999 999 999
Expected Output
Case #1: 2
Case #2: 3
Case #3: 0
Result
RE
我正在解决的问题(应要求)-
问题:
问题
有N栋房子待售。第 i 栋房子需要 Ai 美元购买。您的预算为 B 美元。
您最多可以购买多少套房子?
输入
输入的第一行给出了测试用例的数量,T。接下来是 T 个测试用例。每个测试用例都以包含两个整数 N 和 B 的单行开始。第二行包含 N 个整数。第i个整数是Ai,第i个房子的成本。
输出
对于每个测试用例,输出包含 Case #x: y 的一行,其中 x 是测试用例编号(从 1 开始),y 是您可以购买的最大房屋数量。
查看描述不同语言和包的页面:https://codingcompetitions.withgoogle.com/kickstart/faq。在“平台”部分下查找 Python 3. 规格为
Python 3:
- 3.5.3 (package: python3.5)
- numpy 1.16.2 (pip install numpy)
- scipy 1.2.1 (pip install scipy)
- python3.5 Solution.py
F-strings 和其他一些功能直到 Python 3.6 才引入。将最后一行替换为
print('Case #{}: {}'.format(i + 1, amount))
由于未知原因,系统说我的代码有错误,而我的编辑器运行正常。知道为什么我的代码不起作用吗? (为了更清楚,我正在 kickstart 编辑器中根据给定的输入测试我的程序(而不是提交)。)
case = int(input())
for i in range(case):
price = 0
amount = 0
num, budget = input().split()
houses = sorted(input().split(), key=int)
for house in houses:
price += int(house)
if price > int(budget):
break
amount += 1
print(f'Case #{i+1}: {amount}')
我给测试的输入
Input
3
4 100
20 90 40 90
4 50
30 30 10 10
3 300
999 999 999
Expected Output
Case #1: 2
Case #2: 3
Case #3: 0
Result
RE
我正在解决的问题(应要求)-
问题: 问题 有N栋房子待售。第 i 栋房子需要 Ai 美元购买。您的预算为 B 美元。
您最多可以购买多少套房子?
输入 输入的第一行给出了测试用例的数量,T。接下来是 T 个测试用例。每个测试用例都以包含两个整数 N 和 B 的单行开始。第二行包含 N 个整数。第i个整数是Ai,第i个房子的成本。
输出 对于每个测试用例,输出包含 Case #x: y 的一行,其中 x 是测试用例编号(从 1 开始),y 是您可以购买的最大房屋数量。
查看描述不同语言和包的页面:https://codingcompetitions.withgoogle.com/kickstart/faq。在“平台”部分下查找 Python 3. 规格为
Python 3:
- 3.5.3 (package: python3.5)
- numpy 1.16.2 (pip install numpy)
- scipy 1.2.1 (pip install scipy)
- python3.5 Solution.py
F-strings 和其他一些功能直到 Python 3.6 才引入。将最后一行替换为
print('Case #{}: {}'.format(i + 1, amount))