码迷,mamicode.com
首页 > 其他好文 > 详细

Holes in the text Add problem to Todo list Problem code: HOLES

时间:2015-05-05 18:32:35      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

 1 import sys
 2 
 3 
 4 def count_holes(letter):
 5     hole_2 = [A, D, O, P, Q, R]
 6     if letter == B:
 7         return 2
 8     elif letter in hole_2:
 9         return 1
10     else:
11         return 0
12 
13 
14 def main():
15     n = int(sys.stdin.readline())
16     for t in sys.stdin:
17         num = 0
18         for l in t[:-1]:
19             num += count_holes(l)
20         print num
21 
22 
23 main()

 

 

学习

  raw_input( )和sys.stdin.readline( ) 区别

    raw_input()不包含最后\n的换行符号,而后者有

    sys.stdin.readline( ).strip(),没有参数,默认去除首尾空格、换行符号

    .spilt()再加一个,依照空格,对输入的数据进行分割

  IDE

    debug的理解

    console输入不能立即回显

      因为pycharm启用了缓冲,为了高效

  psyco.full()

    有时确实会导致RE

  良好的代码缩进和空格

  预定义方式更快

    if a in b[]

  for循环

    没问题,可以挨个循环String, 如果不想要\n(本题随不影响结果,但是多一次函数调用),用[:-1],这种:操作是py一个很大的好处

  这次构思和调试都是自己独立完成

    加油!

错误
     elif (‘A‘ or ‘D‘ or ‘O‘ or ‘P‘ or ‘Q‘ or ‘R‘) == letter: 逻辑判断有错,不能判断A以后的,不能使用

  

  

Holes in the text Add problem to Todo list Problem code: HOLES

标签:

原文地址:http://www.cnblogs.com/sangocare/p/4479636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!