Python 板


LINE

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







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP