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

1234567891011121314151617181920212223242526272829303132333435
  1. class SeatPass:
  2. def __init__(self, seatcode):
  3. self.getrow(seatcode[:7])
  4. self.getcol(seatcode[7:])
  5. self.getseat()
  6. def getrow(self, seatcode):
  7. seatcode = seatcode.replace('F', '0')
  8. seatcode = seatcode.replace('B', '1')
  9. self.row = int(seatcode, 2)
  10. def getcol(self, seatcode):
  11. seatcode = seatcode.replace('L', '0')
  12. seatcode = seatcode.replace('R', '1')
  13. self.col = int(seatcode, 2)
  14. def getseat(self):
  15. self.seatnum = (self.row * 8) + self.col
  16. def main():
  17. with open('input5.txt') as file:
  18. lines = file.readlines()
  19. lines = [line.strip() for line in lines]
  20. passes = []
  21. maxseat = -1
  22. for line in lines:
  23. p = SeatPass(line)
  24. passes.append(p)
  25. if p.seatnum > maxseat:
  26. maxseat = p.seatnum
  27. print(f"The largest seat number I've seen is {maxseat}.")
  28. if __name__ == "__main__":
  29. main()