python - 针对 USACO 问题的 Python 代码中的 EOF 错误重新植被
问题描述
我一直在研究 USACO 问题,到目前为止我有这个代码:
fin = open('revegetate.in', 'r')
fout = open('revegetate.out', 'w')
pasture_num, cow_num = map(int, input().split())
pastures = []
ans = [1] * pasture_num
for _ in range(cow_num):
past1, past2 = sorted(map(int, input().split()))
pastures.append([past1 - 1, past2 - 1])
pastures.sort()
for a, b in pastures:
if ans[a] == ans[b]:
ans[b] += 1
for i, j in pastures[:pastures.index([a, b])]:
if ans[i] == ans[j]:
ans[b] += 1
print(''.join(map(str, and)))
虽然当我运行它时,它会在第 4 行返回 EOF 错误:
pasture_num, cow_num = map(int, input().split())
样本输入将是:
5 6
4 1
4 2
4 3
2 5
1 2
1 5
如何修复此 EOF 错误?
解决方案
我通过将其更改为 fin.readline() 而不是 input() 来修复它。
推荐阅读
- android - NullPointerException 响应使用改造
- reactjs - React redux 不显示地图内容
- oracle-apex - oracle apex 18.2 pl/sql 函数体返回 sql 查询检查页面项目值
- azure-cosmosdb - Cosmosdb Resource Token Authorization Header using a REST call
- html - 显示源文件夹中的图像
- web-services - Google Places Autocomplete(包含在 Places 详细信息中)在使用会话令牌时未触发 SKU
- directx - HLSL 自定义位打包无法正常工作
- c# - Web API:从 Get 返回的数组长度为零
- python - Weird issue with regex match
- javascript - trying to remove padding from the ul tag of the popup