Advertisement
GeorgiLukanov87

shit_happens

Aug 1st, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.08 KB | None | 0 0
  1. ################################################################################################################
  2.  
  3. # 05. HTML
  4.  
  5. title = input()
  6. print(f'<h1>\n    {title}\n</h1>')
  7.  
  8. contest = input()
  9. print(f'<article>\n    {contest}\n</article>')
  10.  
  11. comments = input()
  12.  
  13. while not comments == 'end of comments':
  14.     print(f'<div>\n    {comments}\n</div>')
  15.  
  16.     comments = input()
  17.  
  18. ################################################################################################################
  19.    
  20.  
  21. # 04. Morse Code Translator
  22.  
  23.  
  24. MORSE_CODE_DICT = {'A': '.-', 'B': '-...',
  25.                    'C': '-.-.', 'D': '-..', 'E': '.',
  26.                    'F': '..-.', 'G': '--.', 'H': '....',
  27.                    'I': '..', 'J': '.---', 'K': '-.-',
  28.                    'L': '.-..', 'M': '--', 'N': '-.',
  29.                    'O': '---', 'P': '.--.', 'Q': '--.-',
  30.                    'R': '.-.', 'S': '...', 'T': '-',
  31.                    'U': '..-', 'V': '...-', 'W': '.--',
  32.                    'X': '-..-', 'Y': '-.--', 'Z': '--..',
  33.                    '1': '.----', '2': '..---', '3': '...--',
  34.                    '4': '....-', '5': '.....', '6': '-....',
  35.                    '7': '--...', '8': '---..', '9': '----.',
  36.                    '0': '-----', ', ': '--..--', '.': '.-.-.-',
  37.                    '?': '..--..', '/': '-..-.', '-': '-....-',
  38.                    '(': '-.--.', ')': '-.--.-'}
  39.  
  40.  
  41. # # Function to encrypt the string
  42. # # according to the morse code chart
  43. # def encrypt(message):
  44. #     cipher = ''
  45. #     for letter in message:
  46. #         if letter != ' ':
  47. #
  48. #             # Looks up the dictionary and adds the
  49. #             # corresponding morse code
  50. #             # along with a space to separate
  51. #             # morse codes for different characters
  52. #             cipher += MORSE_CODE_DICT[letter] + ' '
  53. #         else:
  54. #             # 1 space indicates different characters
  55. #             # and 2 indicates different words
  56. #             cipher += ' '
  57. #
  58. #     return cipher
  59.  
  60. #
  61. # Function to decrypt the string
  62. # from morse to english
  63. def decrypt(message):
  64.     # extra space added at the end to access the
  65.     # last morse code
  66.     message += ' '
  67.  
  68.     decipher = ''
  69.     citext = ''
  70.     for letter in message:
  71.  
  72.         # checks for space
  73.         if (letter != ' '):
  74.  
  75.             # counter to keep track of space
  76.             i = 0
  77.  
  78.             # storing morse code of a single character
  79.             citext += letter
  80.  
  81.         # in case of space
  82.         else:
  83.             # if i = 1 that indicates a new character
  84.             i += 1
  85.  
  86.             # if i = 2 that indicates a new word
  87.             if i == 2:
  88.  
  89.                 # adding space to separate words
  90.                 decipher += ' '
  91.             else:
  92.  
  93.                 # accessing the keys using their values (reverse of encryption)
  94.                 decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT
  95.                                                               .values()).index(citext)]
  96.                 citext = ''
  97.  
  98.     return decipher
  99.  
  100.  
  101. message = input().split("|")
  102. for char in message:
  103.     char = char.strip()
  104.     print(decrypt(char), end=" ")
  105.  
  106.    
  107. ################################################################################################################
  108.  
  109. #  02. ASCII Sumator
  110.  
  111.  
  112. start_symbol = input()
  113. end_symbol = input()
  114. random_string = input()
  115. searched_chars = []
  116.  
  117. for valid_chars in range(ord(start_symbol) + 1, ord(end_symbol)):
  118.     searched_chars.append(chr(valid_chars))
  119.  
  120. final_string = []
  121.  
  122. for char in random_string:
  123.     if char in searched_chars:
  124.         final_string.append(ord(char))
  125.  
  126. print(sum(final_string))
  127.  
  128.  
  129. ################################################################################################################
  130.  
  131.  
  132. # 01. Extract Person Information
  133.  
  134.  
  135. n = int(input())
  136. key_words = []
  137.  
  138. for text in range(n):
  139.     string_data = input().split(' ')
  140.     for name in string_data:
  141.         if '@' in name:
  142.             key_words += [name]
  143.     for age in string_data:
  144.         if '#' in age:
  145.             key_words += [age]
  146.  
  147.     start_index_name = key_words[0].index('@')
  148.     end_index_name = key_words[0].index('|')
  149.  
  150.     start_index_age = key_words[1].index('#')
  151.     end_index_age = key_words[1].index('*')
  152.  
  153.     final_name = key_words[0][start_index_name + 1:end_index_name]
  154.     final_age = key_words[1][start_index_age + 1:end_index_age]
  155.     print(f'{final_name} is {final_age} years old.')
  156.  
  157.     key_words.clear()
  158.  
  159.    
  160. ################################################################################################################
  161.  
  162.  
  163.  
  164. # 03. Star Enigma
  165.  
  166. def count_letters(some_str: str):
  167.     searched_letters = ['s', 't', 'a', 'r']
  168.     counter_letters = 0
  169.     for char in some_str.lower():
  170.         if char in searched_letters:
  171.             counter_letters += 1
  172.     return counter_letters, some_str
  173.  
  174.  
  175. def decryption(some_str: str, value: int):
  176.     modified_message = ""
  177.     for char in some_str:
  178.         new_char = int(ord(char)) - int(value)
  179.         modified_message += chr(new_char)
  180.     return modified_message
  181.  
  182. import re
  183. n_messages = int(input())
  184.          
  185. pattern = r'.*@([A-z]+)[^\@\-\!\:\>]*:(\d+)[^\@\-\!\:\>]*\!(A|D)\![^\@\-\!\:\>]*\->(\d+).*'
  186. attacked_planets = []
  187. destroyed_planets = []
  188.  
  189. for _ in range(n_messages):
  190.     message = input()
  191.     keys, cleaned_message = count_letters(message)
  192.     decrypted_message = decryption(cleaned_message, keys)
  193.     valid_info = re.findall(pattern, decrypted_message)
  194.  
  195.     if valid_info:
  196.         name = valid_info[0][0]
  197.         attack_type = valid_info[0][2]
  198.  
  199.         if attack_type == 'A':
  200.             attacked_planets.append(name)
  201.            
  202.         elif attack_type == 'D':
  203.             destroyed_planets.append(name)
  204.  
  205. print(f'Attacked planets: {len(attacked_planets)}')
  206. for att_planet in sorted(attacked_planets):
  207.     print(f'-> {att_planet}')
  208.  
  209. print(f'Destroyed planets: {len(destroyed_planets)}')
  210. for destr_planet in sorted(destroyed_planets):
  211.     print(f'-> {destr_planet}')
  212.    
  213.    
  214. ################################################################################################################
  215.  
  216.  
  217. # 04. Nether Realms
  218.  
  219. import re
  220.  
  221. data = re.split(", *", input())
  222. demons_collection = {}
  223.  
  224. demon_health_pattern = r'[^\d\+\-*\/\.]'
  225. demon_damage_pattern = r'(?:\+|-)?[0-9]+(?:\.[0-9]+)?'
  226. operators_pattern = r'[*\/]'
  227.  
  228. for demon_name in data:
  229.     demon_name = demon_name.strip()
  230.     demon_health = re.findall(demon_health_pattern, demon_name)
  231.     demons_collection[demon_name] = []
  232.     demons_collection[demon_name].append(sum(ord(match) for match in demon_health))
  233.  
  234.     demon_damage = re.finditer(demon_damage_pattern, demon_name)
  235.     operators = re.findall(operators_pattern, demon_name)
  236.     damage = 0
  237.  
  238.     for amount in demon_damage:
  239.         damage += float(amount.group(0))
  240.  
  241.     for current_operator in operators:
  242.         if current_operator == '*':
  243.             damage *= 2
  244.         elif current_operator == '/':
  245.             damage /= 2
  246.  
  247.     demons_collection[demon_name].append(damage)
  248.  
  249. for demon_name, hlt_dmg in sorted(demons_collection.items()):
  250.     print(f'{demon_name} - {hlt_dmg[0]} health, {hlt_dmg[1]:.2f} damage')
  251.  
  252.  
  253. ################################################################################################################
  254.  
  255.  
  256. # 05. HTML Parser
  257.  
  258.  
  259. import re
  260.  
  261. pattern_title = r'<title>([^<>]*)<\/title>'
  262.  
  263. info = input()
  264.  
  265. matched_title = re.findall(pattern_title, info)
  266. matched_title = ''.join(matched_title)
  267. print(f"Title: {matched_title}")
  268.  
  269. pattern_body = r'<body>.*<\/body>'
  270.  
  271. matched_body = re.findall(pattern_body, info)
  272.  
  273. matched_body = ''.join(matched_body)
  274.  
  275. content = r">([^><]*)<"
  276.  
  277. matched_content = re.findall(content, matched_body)
  278.  
  279. matched_content = ''.join(matched_content)
  280. matched_content = matched_content.replace('\\n', '')
  281.  
  282. print(f'Content: {matched_content}')
  283.  
  284.  
  285. ################################################################################################################
  286.  
  287.  
  288. # 03. MOBA Challenger
  289.  
  290.  
  291. def is_players_valid(some_dict: dict, player_one: str, player_two: str):
  292.     if player_one and player_two in some_dict.keys():
  293.         return True
  294.     return False
  295.  
  296.  
  297. def calculate_total_skill_points(some_dict: dict):
  298.     total_skill_points = {}
  299.     for current_name, skills in some_dict.items():
  300.         for current_position, skill_point in skills.items():
  301.             current_skill_points = int(skill_point)
  302.             if current_name not in total_skill_points:
  303.                 total_skill_points[current_name] = current_skill_points
  304.             else:
  305.                 total_skill_points[current_name] += current_skill_points
  306.     return total_skill_points
  307.  
  308.  
  309. def time_for_duel(some_dict: dict, player_one, player_two):
  310.     player1_common = []
  311.     player2_common = []
  312.  
  313.     for key1, skills1 in some_dict[player_one].items():
  314.         if key1 not in player1_common:
  315.             player1_common.append(key1)
  316.  
  317.     for key2, skills2 in some_dict[player_two].items():
  318.         if key2 not in player2_common:
  319.             player2_common.append(key2)
  320.  
  321.     for el in player1_common:
  322.         if el in player2_common:
  323.             if some_dict[player_one][el] > some_dict[player_two][el]:
  324.                 del some_dict[player_two]
  325.                 del total_skills_points[player_two]
  326.             else:
  327.                 del some_dict[player_one]
  328.                 del total_skills_points[player_one]
  329.     return some_dict
  330.  
  331.  
  332. data = input()
  333. my_dict = {}
  334. total_skills_points = {}
  335. while not data == 'Season end':
  336.     if ' -> ' in data:
  337.         details = data.split(" -> ")
  338.         player = details[0]
  339.         position = details[1]
  340.         skill_points = int(details[2])
  341.         if player not in my_dict.keys():
  342.             my_dict[player] = {position: skill_points}
  343.         else:
  344.             if position not in my_dict[player]:
  345.                 my_dict[player].update({position: skill_points})
  346.             else:
  347.                 old_score = my_dict[player][position]
  348.                 my_dict[player].update({position: max(skill_points, old_score)})
  349.  
  350.  
  351.     elif ' vs ' in data:
  352.         details = data.split(' vs ')
  353.         player1 = details[0]
  354.         player2 = details[1]
  355.         if is_players_valid(my_dict, player1, player2):
  356.             my_dict = time_for_duel(my_dict, player1, player2)
  357.  
  358.     total_skills_points = (calculate_total_skill_points(my_dict))
  359.     data = input()
  360.  
  361. for name, points in sorted(total_skills_points.items(), key=lambda kv: (-kv[1], kv[0])):
  362.     print(f'{name}: {points} skill')
  363.     for name1, points1 in sorted(my_dict[name].items(), key=lambda kv: (-kv[1], kv[0])):
  364.         print(f'- {name1} <::> {points1}')
  365.  
  366.        
  367.        
  368. ################################################################################################################
  369.  
  370.  
  371. # 04. Snow White
  372.  
  373. items = input()
  374. my_dwarfs = {}
  375. hat_colors = {}
  376.  
  377. while not items == "Once upon a time":
  378.     details = items.split(" <:> ")
  379.     name = details[0]
  380.     color = details[1]
  381.     physics = int(details[2])
  382.    
  383.     id = name + ":" + color
  384.     if id not in my_dwarfs:
  385.         if color not in hat_colors:
  386.             hat_colors[color] = 1
  387.         else:
  388.             hat_colors[color] += 1
  389.         my_dwarfs[id] = [0, color]
  390.     my_dwarfs[id][0] = max([my_dwarfs[id][0], physics])
  391.    
  392.     items = input()
  393.  
  394. sorted_dwrafs = dict(sorted(my_dwarfs.items(), key=lambda x: (x[1][0], hat_colors[x[1][1]]), reverse=True))
  395. for key, value in sorted_dwrafs.items():
  396.     details = key.split(":")
  397.     print(f"({details[1]}) {details[0]} <-> {value[0]}")
  398.  
  399.  
  400. ################################################################################################################
  401.  
  402.  
  403. # 05. Dragon Army
  404.  
  405.  
  406. n_dragons = int(input())
  407. my_dragons = {}
  408. for _ in range(n_dragons):
  409.     details = input().split()
  410.     color_type = details[0]
  411.     name = details[1]
  412.     if not name[0].isupper():
  413.         continue
  414.     damage = details[2]
  415.     if damage == 'null':
  416.         damage = 45
  417.     else:
  418.         damage = int(damage)
  419.     health = details[3]
  420.     if health == 'null':
  421.         health = 250
  422.     else:
  423.         health = int(health)
  424.     armor = details[4]
  425.     if armor == 'null':
  426.         armor = 10
  427.     else:
  428.         armor = int(armor)
  429.  
  430.     if color_type not in my_dragons:
  431.         my_dragons[color_type] = {name: [damage, health, armor]}
  432.     else:
  433.         if name not in my_dragons[color_type]:
  434.             my_dragons[color_type].update({name: [damage, health, armor]})
  435.         else:
  436.             my_dragons[color_type].update({name: [damage, health, armor]})
  437.  
  438. for key, value in my_dragons.items():
  439.     average_sum = [0, 0, 0]
  440.     for dragon, stats in value.items():
  441.         for index, el in enumerate(stats):
  442.             average_sum[index] += el / len(value)
  443.  
  444.     print(key, end="::")
  445.     result = ('/'.join([f"{el:.2f}" for el in average_sum]))
  446.     print(f"({result})")
  447.  
  448.     for dragon1, stats1 in sorted(value.items(), key=lambda x: x[0]):
  449.         result = f"-{dragon1} -> damage: {stats1[0]}, health: {stats1[1]}, armor: {stats1[2]}"
  450.         print(result)
  451.        
  452.        
  453.  
  454. ################################################################################################################
  455.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement