作者KitWoolsey (难得好天气)
看板Python
标题[问题] SPOJ上使用Python 的General I/O?
时间Sat Apr 2 11:30:16 2011
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
1F:→ mjsg:会不会是最後的分行问题,我没仔细看过python的split()他的叙 04/02 11:53
2F:→ mjsg:叙,但是python的split('\n')最後都会多一个''(空字串)… 04/02 11:54
3F:→ mjsg:还是听听别人的意见(只会3k的open後.read().split('\n')[-1] 04/02 11:57
有时候TLE 有时候WA 有时runtime error (NZEC)
我都搞混了....不懂怎麽会这样 写C都不会qq
※ 编辑: KitWoolsey 来自: 218.166.105.130 (04/02 12:03)
4F:→ KSJ:请问什麽是wa什麽是tle什麽是nzec@@a
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)
5F:→ KSJ:看教学查到前两个了XD 04/02 12:59
6F:→ KSJ:default是return None的样子 04/02 13:05
7F:→ KSJ:可以看一下你的ccode吗? 04/02 13:13
8F:→ tkcn:多写几题遇过各类型 input,之後就会很容易了 04/02 14:50
9F:推 cobrasgo:老实说我看不太懂这个python code为何有做到题目所讲的东 04/03 01:21
10F:→ cobrasgo:西,计算!和0的部份在哪里? 04/03 01:22
11F:推 cobrasgo:拍谢,眼残没看到x//5... 04/03 17:31