Issue
My Python program runs without any problems locally, but I receive a runtime error when running it on OJ. All the error messages show exited with code 1
. I wonder what could be the problem.
Here is the link to the question (sorry, it doesn't seem to have an English version): https://www.luogu.com.cn/problem/P5730
1 <= n <= 100
Here is my code:
digits_str_list = [
".XXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX",
".X.X...X...X...X.X.X.X...X.....X.X.X.X.X",
".X.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX",
".X.X...X.X.....X...X...X.X.X...X.X.X...X",
".XXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX"
]
ans = [[] for _ in range(5)]
input() # n
digits = input()
for i in range(5):
for digit in digits:
start_idx = eval(digit) * 4 + 1
ans[i].append(digits_str_list[i][start_idx : start_idx + 3])
print(".".join(ans[i]))
Apologies for my poor English, as it is not my native language. I hope it doesn't affect your reading, and feel free to point out any mistakes in my English.
- using a variable to capture the return value of
input()
, still RE. - encapsulating it in a function and calling it using
if __name__ == '__main__':
, still RE. - Replace
eval(digit)
withint(digit)
.
Solution
The issue has been resolved.
It turns out that there was a problem with the test cases on Luogu OJ. The input contained not only numeric characters but also whitespace characters. I'm really frustrated!
Here is the accepted code.
digits_str_list = [
".XXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX",
".X.X...X...X...X.X.X.X...X.....X.X.X.X.X",
".X.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX",
".X.X...X.X.....X...X...X.X.X...X.X.X...X",
".XXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX",
]
ans = [[] for _ in range(5)]
n = input()
digits = input().strip()
for i in range(5):
for digit in digits:
start_idx = int(digit) * 4 + 1
ans[i].append(digits_str_list[i][start_idx : start_idx + 3])
print(".".join(ans[i]))
Answered By - keikei
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.