基础编程 Python3 来自 Hackerearth 的带有运行时错误的练习题
Basic Programming Python3 practice question with runtime error from Hackerearth
我正在尝试解决一个问题,我应该打印连续重复的特定符号的最大数量,但我必须为每一行手动输入。如果我复制并粘贴测试用例,它会 returns 出错。下面是完整的代码和测试用例,后面给出了输出。
注意:如果没有完全理解问题请访问https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/maximum-border-9767e14c/
def maxborder(a):
maxi=0
for i in range(len(a)):
count=0
for j in range(len(a[0])):
if(a[i][j]=='#'):
count+=1
if count> maxi:
maxi=count
return maxi
no=int(input())
while(no!=0):
m=int(input())
n=int(input())
a=[]
for i in range(m):
r=[]
e=str(input())
if len(e)!=0:
for x in range(len(e)):
r.append(e[x])
a.append(r)
res=maxborder(a)
no-=1
print(res)
测试用例和输出,(下面是完整的测试用例)
TESTCASE:
2 #loop_count(no)
2 15 #row and column(m and n)
.....####......
.....#.........
7 9
...###...
...###...
..#......
.####....
..#......
...#####.
.........
EXPECTED OUTPUT:
4
5
我得到的:
Execution failed.
ValueError: invalid literal for int() with base 10 : '2 15'
Stack Trace:
Traceback (most recent call last):
File "something.py3", line 26, in <module>
m=int(input())
ValueError: invalid literal for int() with base 10: '2 15'
完整测试用例:
10
2 15
.....####......
.....#.........
7 9
...###...
...###...
..#......
.####....
..#......
...#####.
.........
18 11
.#########.
########...
.........#.
####.......
.....#####.
.....##....
....#####..
.....####..
..###......
......#....
....#####..
...####....
##.........
#####......
....#####..
....##.....
.#######...
.#.........
1 15
.....######....
5 11
..#####....
.#######...
......#....
....#####..
...#####...
8 13
.....######..
......##.....
########.....
...#.........
.............
#######......
..######.....
####.........
7 5
.....
..##.
###..
..##.
.....
..#..
.#...
14 2
..
#.
..
#.
..
#.
..
..
#.
..
..
..
#.
..
7 15
.###########...
##############.
...####........
...##########..
.......#.......
.....#########.
.#######.......
12 6
#####.
###...
#.....
##....
###...
......
.##...
..##..
...#..
..#...
#####.
####..
上述测试用例的预期输出:
4
5
9
6
7
8
3
1
14
5
试试这个:
def maxborder(a):
maxi=0
for i in range(len(a)):
count=0
for j in range(len(a[0])):
if(a[i][j]=='#'):
count+=1
if count> maxi:
maxi=count
return maxi
no=int(input())
while(no!=0):
t=input().split(" ")
m=int(t[0])
n=int(t[1])
a=[]
for i in range(m):
r=[]
e=str(input())
if len(e)!=0:
for x in range(len(e)):
r.append(e[x])
a.append(r)
res=maxborder(a)
no-=1
print(res)
我正在尝试解决一个问题,我应该打印连续重复的特定符号的最大数量,但我必须为每一行手动输入。如果我复制并粘贴测试用例,它会 returns 出错。下面是完整的代码和测试用例,后面给出了输出。
注意:如果没有完全理解问题请访问https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/maximum-border-9767e14c/
def maxborder(a):
maxi=0
for i in range(len(a)):
count=0
for j in range(len(a[0])):
if(a[i][j]=='#'):
count+=1
if count> maxi:
maxi=count
return maxi
no=int(input())
while(no!=0):
m=int(input())
n=int(input())
a=[]
for i in range(m):
r=[]
e=str(input())
if len(e)!=0:
for x in range(len(e)):
r.append(e[x])
a.append(r)
res=maxborder(a)
no-=1
print(res)
测试用例和输出,(下面是完整的测试用例)
TESTCASE:
2 #loop_count(no)
2 15 #row and column(m and n)
.....####......
.....#.........
7 9
...###...
...###...
..#......
.####....
..#......
...#####.
.........
EXPECTED OUTPUT:
4
5
我得到的:
Execution failed.
ValueError: invalid literal for int() with base 10 : '2 15'
Stack Trace:
Traceback (most recent call last):
File "something.py3", line 26, in <module>
m=int(input())
ValueError: invalid literal for int() with base 10: '2 15'
完整测试用例:
10
2 15
.....####......
.....#.........
7 9
...###...
...###...
..#......
.####....
..#......
...#####.
.........
18 11
.#########.
########...
.........#.
####.......
.....#####.
.....##....
....#####..
.....####..
..###......
......#....
....#####..
...####....
##.........
#####......
....#####..
....##.....
.#######...
.#.........
1 15
.....######....
5 11
..#####....
.#######...
......#....
....#####..
...#####...
8 13
.....######..
......##.....
########.....
...#.........
.............
#######......
..######.....
####.........
7 5
.....
..##.
###..
..##.
.....
..#..
.#...
14 2
..
#.
..
#.
..
#.
..
..
#.
..
..
..
#.
..
7 15
.###########...
##############.
...####........
...##########..
.......#.......
.....#########.
.#######.......
12 6
#####.
###...
#.....
##....
###...
......
.##...
..##..
...#..
..#...
#####.
####..
上述测试用例的预期输出:
4
5
9
6
7
8
3
1
14
5
试试这个:
def maxborder(a):
maxi=0
for i in range(len(a)):
count=0
for j in range(len(a[0])):
if(a[i][j]=='#'):
count+=1
if count> maxi:
maxi=count
return maxi
no=int(input())
while(no!=0):
t=input().split(" ")
m=int(t[0])
n=int(t[1])
a=[]
for i in range(m):
r=[]
e=str(input())
if len(e)!=0:
for x in range(len(e)):
r.append(e[x])
a.append(r)
res=maxborder(a)
no-=1
print(res)