[問題] SPOJ上使用Python 的General I/O?
https://www.spoj.pl/problems/FCTRL/
SPOJ,一個裡面有頗多programming問題的網站
不過當我試圖用Python編寫答案上傳時 總是挫折不斷 = = 連最簡單的問題都很難過
例如這個
https://www.spoj.pl/problems/FCTRL/
很入門的問題, 我用C寫了一個code,輕鬆通過
然而當我用同樣的寫法換成Python時 就一直出錯...Orz
y=input().split()
for i in y[1:]:
x=int(i)
answer = 0
while x > 0 :
x//=5
answer+=x
print(answer)
以上: WA
s=int(input())
for i in range(s):
answer = 0
number = int(input())
while number > 0 :
number//=5
answer+=number
print(answer)
以上: TLE
其他我也試了不少 越試越搞混自己 =.= 不知道到底一般而言I/O應該使用什麼寫法??
還是都要用try/except...@@ 可是這題都知道input有幾個了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.166.105.130
→
04/02 11:53, , 1F
04/02 11:53, 1F
→
04/02 11:54, , 2F
04/02 11:54, 2F
→
04/02 11:57, , 3F
04/02 11:57, 3F
有時候TLE 有時候WA 有時runtime error (NZEC)
我都搞混了....不懂怎麼會這樣 寫C都不會qq
※ 編輯: KitWoolsey 來自: 218.166.105.130 (04/02 12:03)
→
, , 4F
1. AC - accepted - your program ran successfully and gave a correct answer.
Congratulations, you have solved the problem!
2. WA - wrong answer - your program ran successfully, but gave an incorrect
answer. Most probably your program contains a bug, or you are not
interpreting the problem text correctly.
3.TLE - time limit exceeded - your program was compiled successfully, but it
didn't stop before time limit. This may be because the algorithm is badly
designed (too slow), or because it contains a bug, e.g. it goes into an
infinite loop, or hangs up, expecting some input data.
4.CE - compilation error - your program couldn't be compiled; the details of
the compiler error can be accessed from the www interface. Note: only some
programming languages can give a CE, syntax errors in interpreted languages
may instead be displayed as WA (for example, in Python there is no
pre-checking of syntax, and in Perl, CE will only occur sometimes if the
error is detected during a preliminary syntax check).
5. RE - runtime error - your program was compiled successfully, but it exited
with a runtime error or crashed. You will receive an additional error
message, which is most commonly one of the following:
* SIGSEGV (signal 11) - the most common error for non-interpreted
languages: a "segmentation fault" of the program. This may be caused e.g. by
an out-of-scope array index causing a buffer overflow, an incorrectly
initialized pointer, etc.
* SIGXFSZ (signal 25) - "output limit exceeded". Your program has printed
too much data to output (typically more than 25MB).
* SIGFPE (signal 8) - "floating point error" - an error of the arithmetic
co-processor, such as division by zero, etc.
* SIGABRT (signal 6) - raised by the program itself, e.g. by making the
abort() system call. Note that STL in C++ can raise this signal under some
conditions, e.g. due to insufficient memory.
* NZEC (non-zero exit code) - this message means that the program exited
returning a value different from 0 to the shell. For languages such as C,
this probably means you forgot to add "return 0" at the end of the program.
For interpreted languages (including JAVA) NZEC will usually mean that your
program either crashed or raised an uncaught exception.
* other - there are other signals which can cause program to terminate,
all the remaining ones are simply displayed as other.
04/02 12:57
不知道Python有沒有要像C語言一樣加個類似return 0;的東西在最後=.=?
※ 編輯: KitWoolsey 來自: 218.166.111.242 (04/02 13:00)
→
04/02 12:59, , 5F
04/02 12:59, 5F
→
04/02 13:05, , 6F
04/02 13:05, 6F
→
04/02 13:13, , 7F
04/02 13:13, 7F
→
04/02 14:50, , 8F
04/02 14:50, 8F
推
04/03 01:21, , 9F
04/03 01:21, 9F
→
04/03 01:22, , 10F
04/03 01:22, 10F
推
04/03 17:31, , 11F
04/03 17:31, 11F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章