Advertisement
ALEXANDAR_GEORGIEV

Exe_2

May 13th, 2023
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.06 KB | Source Code | 0 0
  1. # Batle_of_names
  2. odd_set = set()
  3. even_set = set()
  4.  
  5. for row in range(1, int(input()) + 1):
  6.     ascii_sum_of_name = sum(ord(l) for l in input()) // row
  7.  
  8.     if ascii_sum_of_name % 2 == 0:
  9.         even_set.add(ascii_sum_of_name)
  10.     else:
  11.         odd_set.add(ascii_sum_of_name)
  12.  
  13. if sum(odd_set) > sum(even_set):
  14.     print(*odd_set.difference(even_set), sep=", ")
  15. else:
  16.     print(*odd_set.symmetric_difference(even_set), sep=", ")
  17.  
  18. # Count_symbols
  19. occurrences = {}
  20.  
  21. for letter in input():
  22.     occurrences[letter] = occurrences.get(letter, 0) + 1
  23.  
  24.  
  25. # Solution 2
  26. for letter in input():
  27.     if letter not in occurrences:
  28.         occurrences[letter] = 0
  29.  
  30.     occurrences[letter] += 1
  31.  
  32. # Solution 3
  33. for letter, times in sorted(occurrences.items()):
  34.     print(f"{letter}: {times} time/s")
  35.  
  36.  
  37. # Solution 4
  38. text = input()
  39.  
  40. for letter in sorted(set(text)):
  41.     print(f'{letter}: {text.count(letter)} time/s')
  42.  
  43. # Crossroads
  44. from collections import deque
  45.  
  46. green_window = int(input())
  47. free_window = int(input())
  48.  
  49. total_cars = 0
  50.  
  51. cars = deque()
  52.  
  53. info = input()
  54.  
  55. while info != "END":
  56.     if info != "green":
  57.         cars.append(info)
  58.     else:
  59.         current_green = green_window
  60.  
  61.         while current_green > 0 and cars:
  62.             car = cars.popleft()
  63.  
  64.             time = current_green + free_window
  65.  
  66.             if len(car) > time:
  67.                 print(f"A crash happened!\n{car} was hit at {car[time]}.")
  68.                 raise SystemExit
  69.  
  70.             current_green -= len(car)
  71.             total_cars += 1
  72.  
  73.     info = input()
  74.  
  75. print(f"Everyone is safe.\n{total_cars} total cars passed the crossroads.")
  76.  
  77. # Cups_and_bottles
  78. from collections import deque
  79.  
  80. cups = deque(int(cup) for cup in input().split())
  81. bottles = deque(int(bottle) for bottle in input().split())
  82.  
  83. wasted_liters = 0
  84.  
  85. while cups and bottles:
  86.     current_cup = cups.popleft()
  87.     current_bottle = bottles.pop()
  88.  
  89.     if current_cup < current_bottle:
  90.         wasted_liters += current_bottle - current_cup
  91.     else:
  92.         cups.appendleft(current_cup - current_bottle)
  93.  
  94. if cups:
  95.     print(f"Cups: {' '.join(str(c) for c in cups)}")
  96. else:
  97.     print(f"Bottles:: {' '.join(str(b) for b in bottles)}")
  98.  
  99. print(f"Wasted litters of water: {wasted_liters}")
  100.  
  101.  
  102. # Longest_intersection
  103. longest_intersection = set()
  104.  
  105. for _ in range(int(input())):
  106.     # first_data, second_data = [map(int, el.split(",")) for el in input().split("-")]
  107.     first_data, second_data = [el.split(",") for el in input().split("-")]
  108.  
  109.     first_range = set(range(int(first_data[0]), int(first_data[1]) + 1))
  110.     second_range = set(range(int(second_data[0]), int(second_data[1]) + 1))
  111.  
  112.     intersection = first_range.intersection(second_range)
  113.  
  114.     if len(intersection) > len(longest_intersection):
  115.         longest_intersection = intersection
  116.  
  117.  
  118. print(f" Longest intersection is "
  119.       f"[{', '.join(str(x) for x in longest_intersection)}]"
  120.       f"with length {len(longest_intersection)}"
  121. )
  122.  
  123.  
  124. # Periodic_table
  125.  
  126. table = set()
  127.  
  128. for _ in range(int(input())):
  129.     for el in input().split():
  130.         table.add(el)
  131.  
  132. print(*table, sep="\n")
  133.  
  134.  
  135.  
  136. # Coment
  137. n = 0
  138. first_set = set()
  139. for _ in range(n):
  140.     first_set.add(int(input()))
  141.  
  142. first_set = {int(input()) for _ in range(n)}
  143.  
  144.  
  145. # Set_of_elements
  146. n, m = [int(num) for num in input().split()]
  147.  
  148. first_set = {int(input()) for _ in range(n)}
  149. second_set = {int(input()) for _ in range(m)}
  150.  
  151. print(first_set.intersection(second_set), sep="\n")
  152.  
  153. # Solution 2
  154. n, m = [int(num) for num in input().split()]
  155.  
  156. first_set = {int(input()) for _ in range(n)}
  157. second_set = {int(input()) for _ in range(m)}
  158.  
  159. print(first_set & second_set, sep="\n")
  160.  
  161. # Solution 3
  162. print(first_set | second_set, sep="\n")
  163.  
  164. # Solution 4
  165. print(first_set - second_set, sep="\n")
  166.  
  167. # Solution 5
  168. print(first_set ^ second_set, sep="\n")
  169.  
  170. # Unique_username
  171. # SETs
  172. # intersection -> сечение
  173. # union -> обединение
  174.  
  175. names_count = int(input())
  176. names = set()
  177.  
  178. for _ in range(names_count):
  179.     names.add(input())
  180.  
  181. print(*names, sep="\n")
  182.  
  183. # КОМЕНТАРИ
  184.  
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement