Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

20 lines
730B

  1. import collections
  2. def strength(hand, order, J_swap='J'):
  3. counter = collections.Counter(hand.replace('J', J_swap))
  4. count = collections.Counter(counter.values())
  5. return [count[n] for n in [5, 4, 3, 2, 1]] + [order.index(k) for k in hand]
  6. text = open(0).read()
  7. data = [ln.split() for ln in text.splitlines()]
  8. order = '123456789TJQKA'
  9. hands = [(strength(hand, order), hand, score) for hand, score in data]
  10. print(sum(rank * int(score) for rank, (_, hand, score) in enumerate(sorted(hands), 1)))
  11. order = 'J123456789TQKA'
  12. hands = [(max(strength(hand, order, J_swap) for J_swap in order[1:]), hand, score) for hand, score in data]
  13. print(sum(rank * int(score) for rank, (_, hand, score) in enumerate(sorted(hands), 1)))