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

 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以后的,不能使用

  

  

时间: 2024-10-01 03:24:13

Holes in the text Add problem to Todo list Problem code: HOLES的相关文章

Turbo Sort Add problem to Todo list Problem code: TSORT

1 def heap_sort(ary): 2 n = len(ary) # 8 3 first = int(n / 2 - 1) # 3 4 for start in range(first, -1, -1): # 3~0 revese 5 max_heapify(ary, start, n - 1) # from start 6 for end in range(n - 1, 0, -1): 7 ary[end], ary[0] = ary[0], ary[end] 8 max_heapif

The Lead Game Add problem to Todo list Problem code: TLG

1 '''def count_lead(first, second): 2 if first > second: 3 return 1, first - second 4 elif first == second: # 题目中没有说明相等的情况 5 return 0, 0 6 else: 7 return 2, second - first''' 8 9 10 def main(): 11 n = int(raw_input()) 12 lead = 0 13 winner = 0 # 有些初始

codechef Holes in the text 题解

Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For exampl

校赛部分水题

1236: xq and Crystal Mine Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 313  Solved: 76 [Submit][Status][Web Board] Description xq once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n>1) is an n?*?n matrix with a diamond inscr

Multi-line NSAttributedString with truncated text

http://stackoverflow.com/questions/7611816/multi-line-nsattributedstring-with-truncated-text/10172794#10172794 Multi-line NSAttributedString with truncated text up vote14down votefavorite 8 I need a UILabel subcass with multiline attributed text with

afterTextChanged() callback being called without the text being actually changed

afterTextChanged() callback being called without the text being actually changed up vote8down votefavorite I have a fragment with an EditText and inside the onCreateView() I add a TextWatcher to the EditText. Each time the fragment is being added for

[PWA] Add Push Notifications to a PWA with React in Chrome and on Android

On Android and in Chrome (but not on iOS), it's possible to send push notifications with a PWA. We'll start by asking the user for permission to send them push notifications, and then look at how to intercept the push event in a service worker. We ca

hidden node and exposed node problem

Exposed node problem In wireless networks, theexposed node problem occurs when a node is prevented from sending packets to other nodes because of a neighboring transmitter. Consider an example of 4 nodes labeled R1, S1, S2, and R2, where the two rece

FZOJ Problem 2148 Moon Game

                                                                                              Problem 2148 Moon Game Problem Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consid