您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

14 行
311B

  1. import re
  2. import sys
  3. ans1 = 0
  4. ans2 = 0
  5. for line in sys.stdin.read().splitlines():
  6. lo, hi, char, pw = re.findall(r'(\d+)-(\d+) (\w): (\w+)', line)[0]
  7. lo, hi = int(lo), int(hi)
  8. ans1 += lo <= pw.count(char) <= hi
  9. ans2 += sum([pw[lo - 1] == char, pw[hi - 1] == char]) == 1
  10. print(ans1)
  11. print(ans2)