Advertisement
ALEXANDAR_GEORGIEV

Examp_prep

Jun 8th, 2023
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. # Christmas_elves
  2. from collections import deque
  3.  
  4. elves = deque([int(x) for x in input().split()])
  5. materials = deque([int(x) for x in input().split()])
  6.  
  7. total_energy = 0
  8. total_toys = 0
  9. iterations = 0
  10.  
  11. while elves and materials:
  12.     elf = elves.popleft()
  13.     material = materials[-1]
  14.  
  15.     if elf < 5:
  16.         continue
  17.  
  18.     iterations += 1
  19.     current_toys_count = 0
  20.  
  21.     if iterations % 3 ==0:
  22.         material *= 2
  23.         current_toys_count += 1
  24.  
  25.     if elf >= material:
  26.         total_energy += material
  27.         elf -= material
  28.  
  29.         if iterations % 5 != 0: # Ако не си на 5-тата итерация даи играчки на елф
  30.             elf += 1
  31.             current_toys_count += 1
  32.  
  33.         else:
  34.             current_toys_count = 0
  35.  
  36.         materials.pop()
  37.  
  38.     else:
  39.         elf *= 2
  40.         current_toys_count = 0
  41.  
  42.     total_toys += current_toys_count
  43.  
  44.     elves.append(elf)
  45.  
  46. print(f"Toys: {total_toys}")
  47. print(f"Energy: {total_energy}")
  48. if elves:
  49.     print(f"Elves left: {', '.join(str(x) for x in elves)}")
  50. if materials:
  51.     print(f"Boxes left: {', '.join(str(x) for x in materials)}")
  52.  
  53.  
  54. # Pawn_wars
  55.  
  56. SIZE = 8
  57. # Ako Редовете между белите и черните са четен брой -> печелят винаги белите
  58. # Ako Редовете между белите и черните са neчетен брой -> печелят винаги `черните
  59. board = []
  60. positions = [[], []]
  61.  
  62. def save_positions(search_for, index_to_save, r):
  63.     if search_for in board[r]:
  64.         positions[index_to_save].append(r)
  65.         positions[index_to_save].append(board[r].index(search_for))
  66.  
  67.  
  68. for row in range(SIZE):
  69.     board.append([input().split()])
  70.  
  71.     save_positions("w", 0, row)
  72.     save_positions("b", 1, row)
  73.  
  74. if abs(positions[0][1] - positions[1][1]) != 1 or positions[1][0] > positions[0][0]:
  75.     if SIZE - positions[0][0] - 1 <= positions[1][0]:   # -1 защото индекс 8 е невалиден индекс и белите винаги започват 1-ви
  76.         print(f"Game over! Black pawn promoted to a queen at {chr(97 + positions[1][1])}1.")
  77.     else:
  78.         print(f"Game over! White pawn promoted to a queen at {chr(97 + positions[0][1])}8.")
  79.  
  80. else:
  81.     place = (positions[0][0] + positions[1][0]) // 2
  82.     # Ако и двете са на нечетни или на четни -> винаги печелят четрните
  83.     if positions[0][0] % 2 == 0 and positions[1][0] % 2:
  84.         print(f"Game over! Black win, capture on {chr(97 + positions[0][1])}{SIZE - place}.")  # черните печелят но на колоната на белите, защото взимат пешката
  85.     else:
  86.         print(f"Game over! White win, capture on {chr(97 + positions[1][1])}{SIZE - place}.")
  87.  
  88. # Words_sorting
  89.  
  90. def words_sorting(*words):
  91.     words_dict = {word: sum(map(ord, word)) for word in words}  # map -> ord(letter) for letter in word
  92.  
  93.     if sum(words_dict.values()) % 2 ==0:
  94.         return "\n".join([f"{w} - {s}" for w, s in sorted(words_dict.items(), key=lambda x: x[0])])
  95.  
  96.     return "\n".join([f"{w} - {s}" for w, s in sorted(words_dict.items(), key=lambda x: -x[0])])
  97.  
  98. # ___________________________ Няма Викане на функцията ??
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement