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

2 年前
12345678910111213141516171819202122
  1. text = open(0).read()
  2. cycles = [1]
  3. for ln in map(str.split, text.splitlines()):
  4. match ln:
  5. case ['addx', i]:
  6. cycles.extend([0, int(i)])
  7. case ['noop']:
  8. cycles.extend([0])
  9. ans1 = 0
  10. ans2, W, H = '', 40, 6
  11. for y in range(H):
  12. for x in range(W):
  13. i = 1 + y * W + x
  14. p = sum(cycles[:i])
  15. if i % 40 == 20:
  16. ans1 += i * p
  17. ans2 += '##' if abs(x - p) <= 1 else ' '
  18. ans2 += '\n'
  19. print(ans1)
  20. print(ans2)