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

时间:2023-03-09 08:16:43
Holes in the text  Add problem to Todo list Problem code: HOLES
 import sys

 def count_holes(letter):
hole_2 = ['A', 'D', 'O', 'P', 'Q', 'R']
if letter == 'B':
return 2
elif letter in hole_2:
return 1
else:
return 0 def main():
n = int(sys.stdin.readline())
for t in sys.stdin:
num = 0
for l in t[:-1]:
num += count_holes(l)
print num 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以后的,不能使用