Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

20 Zeilen
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)))