[問題] SPOJ上使用Python 的General I/O?

看板Python作者 (難得好天氣)時間14年前 (2011/04/02 11:30), 編輯推噓2(209)
留言11則, 4人參與, 最新討論串1/2 (看更多)
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
會不會是最後的分行問題,我沒仔細看過python的split()他的敘
04/02 11:53, 1F

04/02 11:54, , 2F
敘,但是python的split('\n')最後都會多一個''(空字串)…
04/02 11:54, 2F

04/02 11:57, , 3F
還是聽聽別人的意見(只會3k的open後.read().split('\n')[-1]
04/02 11:57, 3F
有時候TLE 有時候WA 有時runtime error (NZEC) 我都搞混了....不懂怎麼會這樣 寫C都不會qq ※ 編輯: KitWoolsey 來自: 218.166.105.130 (04/02 12:03)

, , 4F
請問什麼是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)

04/02 12:59, , 5F
看教學查到前兩個了XD
04/02 12:59, 5F

04/02 13:05, , 6F
default是return None的樣子
04/02 13:05, 6F

04/02 13:13, , 7F
可以看一下你的ccode嗎?
04/02 13:13, 7F

04/02 14:50, , 8F
多寫幾題遇過各類型 input,之後就會很容易了
04/02 14:50, 8F

04/03 01:21, , 9F
老實說我看不太懂這個python code為何有做到題目所講的東
04/03 01:21, 9F

04/03 01:22, , 10F
西,計算!和0的部份在哪裡?
04/03 01:22, 10F

04/03 17:31, , 11F
拍謝,眼殘沒看到x//5...
04/03 17:31, 11F
文章代碼(AID): #1DbfXARe (Python)
文章代碼(AID): #1DbfXARe (Python)