- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试解决问题,但 Hackerrank 的编译器在解析时不断抛出错误 EOFError:不知道哪里错了。
#!usr/bin/python
b=[]
b=raw_input().split()
c=[]
d=[]
a=raw_input()
c=a.split()
f=b[1]
l=int(b[1])
if(len(c)==int(b[0])):
for i in range(l,len(c)):
d.append(c[i])
#print c[i]
for i in range(int(f)):
d.append(c[i])
#print c[i]
for j in range(len(d)):
print d[j],
我也尝试过 try catch 来解决它,但没有得到任何输入。
try:
a=input()
c=a.split()
except(EOFError):
a=""
输入格式是开头为 2 个空格的整数,然后是数组
回溯错误是:
Traceback (most recent call last):
File "solution.py", line 4, in <module>
b=raw_input().split()
EOFError: EOF when reading a line
最佳答案
有多种方法可以处理 EOF 错误。
1.抛出异常:
while True:
try:
value = raw_input()
do_stuff(value) # next line was found
except (EOFError):
break #end of file reached
2.检查输入内容:
while True:
value = raw_input()
if (value != ""):
do_stuff(value) # next line was found
else:
break
3.使用 sys.stdin.readlines() 将它们转换为列表,然后使用 for-each 循环。更详细的解释是Why does standard input() cause an EOF error
import sys
# Read input and assemble Phone Book
n = int(input())
phoneBook = {}
for i in range(n):
contact = input().split(' ')
phoneBook[contact[0]] = contact[1]
# Process Queries
lines = sys.stdin.readlines() # convert lines to list
for i in lines:
name = i.strip()
if name in phoneBook:
print(name + '=' + str( phoneBook[name] ))
else:
print('Not found')
关于python - python Hackerrank 中的 EOF 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43077261/
function birthdayCakeCandles(n, ar) { let max = 0; for(let i = 0; i max) { max = ar[i];
我正在尝试解决 https://www.hackerrank.com/challenges/find-hackerrank在 Obj-C 上,并通过 xCode 获得正常输出,但不是通过 hacker
我一直在努力解决这个挑战,并且有点想知道该怎么做。但是经过我所有的尝试,我只能通过测试用例,并且在提交面板中还有一个案例。之后一切都失败了 问题: 一家公司要求简化其产品分配策略,给定 n 个产品,每
问题陈述 :Sherlock and Moving Tiles TL;博士 : 给定 2 正方形;边长为 L,放置在 x-y 平面中,两个正方形 搬家沿线 y=x (沿正 x 和 y)速度为 S1 和
这个问题与this challenge有关在 HackerRank 上。它似乎在某些情况下失败了,但我不清楚算法有什么问题(很多人似乎有超时问题,这不是问题,一切都运行得很快,我看到的所有情况都通过了
我一直在应对这个挑战: Count Triplets ,经过大量的努力,我的算法并没有适用于每个测试用例。 由于在讨论中,我看到了一段代码并试图找出代码的真正功能,但我仍然无法理解这段代码是如何工作的
请参阅最近在 HackerRank 上发布的以下问题 Adam is standing at point (a,b) in an infinite 2D grid. He wants to know
(HakerRank) task是让我格式化测试用例给出的输入。 字符串和整数之间需要有 15 个空格,并且如果只有两位数,则在整数前面附加一个零,我的代码据我所知完成了这一点,并与预期的输出匹配,但
大多数人可能熟悉这个问题,但对于那些不熟悉的人来说: Given 32-bit unsigned integers flip their bits and print the resulting in
给定一个未排序的整数列表,找到它们之间绝对差最小的一对元素。如果有多对,请全部找到。 我的推理是将每个:arr[j] - arr[i] 与lowest 进行比较,如果它小于或等于该值,则将该值添加到数
我正在解决重复字符串 hackerrank 问题。但是所有的测试用例都没有运行可能是我的逻辑不正确。问题是这样的 下面给出了我的代码,其中包含没有变量的repeatedString和countingA
问题的链接如下: https://www.hackerrank.com/challenges/strange-code/problem static long strangeCounter(long
我正在尝试解决this hackerrank 上的问题,我花了一段时间才找到窍门。 技巧在于异或的属性以及数字出现在数组子集中的次数,其中子集是连续的(请注意)。 因此,如果我们有 1,2,3,子集将
我无法理解代码中这一行的用法,有人可以解释一下这个问题或提供一些不同的方法来解决这个问题 问题链接:https://www.hackerrank.com/challenges/15-days-of-l
为了问题陈述,我附上了两张照片。 /image/22zyM.png /image/5c8e6.png 我的代码: for(i=0;i #include #include #include int
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我试图解决this 。我的算法在离线编译器中给出了正确的答案。我不知道错误在哪里。我对 C 语言完全陌生。 该问题要求创建一个函数来查找方阵左右对角线的绝对差。 这是我的网站解决方案。当我在线运行代码
我想创建一个函数来返回一个数组,其中包含完成另一个数组所需的步骤数,但有一个小条件,我只想在 0 上执行步骤,这意味着如果我有数组 c = [0,0 ,0,1,0,0,1,0] 它将把前三个 0 作为
我正在尝试 hackerrank 中的 Morgan and a String 挑战( https://www.hackerrank.com/challenges/morgan-and-a-strin
我是初学者,欢迎替代此代码。输入值后程序崩溃。我也想更多地了解这个问题,因为我已经看过很多次了。 #include #include #include #include using namespace
我是一名优秀的程序员,十分优秀!