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灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP