Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################################################
- # 05. HTML
- title = input()
- print(f'<h1>\n {title}\n</h1>')
- contest = input()
- print(f'<article>\n {contest}\n</article>')
- comments = input()
- while not comments == 'end of comments':
- print(f'<div>\n {comments}\n</div>')
- comments = input()
- ################################################################################################################
- # 04. Morse Code Translator
- MORSE_CODE_DICT = {'A': '.-', 'B': '-...',
- 'C': '-.-.', 'D': '-..', 'E': '.',
- 'F': '..-.', 'G': '--.', 'H': '....',
- 'I': '..', 'J': '.---', 'K': '-.-',
- 'L': '.-..', 'M': '--', 'N': '-.',
- 'O': '---', 'P': '.--.', 'Q': '--.-',
- 'R': '.-.', 'S': '...', 'T': '-',
- 'U': '..-', 'V': '...-', 'W': '.--',
- 'X': '-..-', 'Y': '-.--', 'Z': '--..',
- '1': '.----', '2': '..---', '3': '...--',
- '4': '....-', '5': '.....', '6': '-....',
- '7': '--...', '8': '---..', '9': '----.',
- '0': '-----', ', ': '--..--', '.': '.-.-.-',
- '?': '..--..', '/': '-..-.', '-': '-....-',
- '(': '-.--.', ')': '-.--.-'}
- # # Function to encrypt the string
- # # according to the morse code chart
- # def encrypt(message):
- # cipher = ''
- # for letter in message:
- # if letter != ' ':
- #
- # # Looks up the dictionary and adds the
- # # corresponding morse code
- # # along with a space to separate
- # # morse codes for different characters
- # cipher += MORSE_CODE_DICT[letter] + ' '
- # else:
- # # 1 space indicates different characters
- # # and 2 indicates different words
- # cipher += ' '
- #
- # return cipher
- #
- # Function to decrypt the string
- # from morse to english
- def decrypt(message):
- # extra space added at the end to access the
- # last morse code
- message += ' '
- decipher = ''
- citext = ''
- for letter in message:
- # checks for space
- if (letter != ' '):
- # counter to keep track of space
- i = 0
- # storing morse code of a single character
- citext += letter
- # in case of space
- else:
- # if i = 1 that indicates a new character
- i += 1
- # if i = 2 that indicates a new word
- if i == 2:
- # adding space to separate words
- decipher += ' '
- else:
- # accessing the keys using their values (reverse of encryption)
- decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT
- .values()).index(citext)]
- citext = ''
- return decipher
- message = input().split("|")
- for char in message:
- char = char.strip()
- print(decrypt(char), end=" ")
- ################################################################################################################
- # 02. ASCII Sumator
- start_symbol = input()
- end_symbol = input()
- random_string = input()
- searched_chars = []
- for valid_chars in range(ord(start_symbol) + 1, ord(end_symbol)):
- searched_chars.append(chr(valid_chars))
- final_string = []
- for char in random_string:
- if char in searched_chars:
- final_string.append(ord(char))
- print(sum(final_string))
- ################################################################################################################
- # 01. Extract Person Information
- n = int(input())
- key_words = []
- for text in range(n):
- string_data = input().split(' ')
- for name in string_data:
- if '@' in name:
- key_words += [name]
- for age in string_data:
- if '#' in age:
- key_words += [age]
- start_index_name = key_words[0].index('@')
- end_index_name = key_words[0].index('|')
- start_index_age = key_words[1].index('#')
- end_index_age = key_words[1].index('*')
- final_name = key_words[0][start_index_name + 1:end_index_name]
- final_age = key_words[1][start_index_age + 1:end_index_age]
- print(f'{final_name} is {final_age} years old.')
- key_words.clear()
- ################################################################################################################
- # 03. Star Enigma
- def count_letters(some_str: str):
- searched_letters = ['s', 't', 'a', 'r']
- counter_letters = 0
- for char in some_str.lower():
- if char in searched_letters:
- counter_letters += 1
- return counter_letters, some_str
- def decryption(some_str: str, value: int):
- modified_message = ""
- for char in some_str:
- new_char = int(ord(char)) - int(value)
- modified_message += chr(new_char)
- return modified_message
- import re
- n_messages = int(input())
- pattern = r'.*@([A-z]+)[^\@\-\!\:\>]*:(\d+)[^\@\-\!\:\>]*\!(A|D)\![^\@\-\!\:\>]*\->(\d+).*'
- attacked_planets = []
- destroyed_planets = []
- for _ in range(n_messages):
- message = input()
- keys, cleaned_message = count_letters(message)
- decrypted_message = decryption(cleaned_message, keys)
- valid_info = re.findall(pattern, decrypted_message)
- if valid_info:
- name = valid_info[0][0]
- attack_type = valid_info[0][2]
- if attack_type == 'A':
- attacked_planets.append(name)
- elif attack_type == 'D':
- destroyed_planets.append(name)
- print(f'Attacked planets: {len(attacked_planets)}')
- for att_planet in sorted(attacked_planets):
- print(f'-> {att_planet}')
- print(f'Destroyed planets: {len(destroyed_planets)}')
- for destr_planet in sorted(destroyed_planets):
- print(f'-> {destr_planet}')
- ################################################################################################################
- # 04. Nether Realms
- import re
- data = re.split(", *", input())
- demons_collection = {}
- demon_health_pattern = r'[^\d\+\-*\/\.]'
- demon_damage_pattern = r'(?:\+|-)?[0-9]+(?:\.[0-9]+)?'
- operators_pattern = r'[*\/]'
- for demon_name in data:
- demon_name = demon_name.strip()
- demon_health = re.findall(demon_health_pattern, demon_name)
- demons_collection[demon_name] = []
- demons_collection[demon_name].append(sum(ord(match) for match in demon_health))
- demon_damage = re.finditer(demon_damage_pattern, demon_name)
- operators = re.findall(operators_pattern, demon_name)
- damage = 0
- for amount in demon_damage:
- damage += float(amount.group(0))
- for current_operator in operators:
- if current_operator == '*':
- damage *= 2
- elif current_operator == '/':
- damage /= 2
- demons_collection[demon_name].append(damage)
- for demon_name, hlt_dmg in sorted(demons_collection.items()):
- print(f'{demon_name} - {hlt_dmg[0]} health, {hlt_dmg[1]:.2f} damage')
- ################################################################################################################
- # 05. HTML Parser
- import re
- pattern_title = r'<title>([^<>]*)<\/title>'
- info = input()
- matched_title = re.findall(pattern_title, info)
- matched_title = ''.join(matched_title)
- print(f"Title: {matched_title}")
- pattern_body = r'<body>.*<\/body>'
- matched_body = re.findall(pattern_body, info)
- matched_body = ''.join(matched_body)
- content = r">([^><]*)<"
- matched_content = re.findall(content, matched_body)
- matched_content = ''.join(matched_content)
- matched_content = matched_content.replace('\\n', '')
- print(f'Content: {matched_content}')
- ################################################################################################################
- # 03. MOBA Challenger
- def is_players_valid(some_dict: dict, player_one: str, player_two: str):
- if player_one and player_two in some_dict.keys():
- return True
- return False
- def calculate_total_skill_points(some_dict: dict):
- total_skill_points = {}
- for current_name, skills in some_dict.items():
- for current_position, skill_point in skills.items():
- current_skill_points = int(skill_point)
- if current_name not in total_skill_points:
- total_skill_points[current_name] = current_skill_points
- else:
- total_skill_points[current_name] += current_skill_points
- return total_skill_points
- def time_for_duel(some_dict: dict, player_one, player_two):
- player1_common = []
- player2_common = []
- for key1, skills1 in some_dict[player_one].items():
- if key1 not in player1_common:
- player1_common.append(key1)
- for key2, skills2 in some_dict[player_two].items():
- if key2 not in player2_common:
- player2_common.append(key2)
- for el in player1_common:
- if el in player2_common:
- if some_dict[player_one][el] > some_dict[player_two][el]:
- del some_dict[player_two]
- del total_skills_points[player_two]
- else:
- del some_dict[player_one]
- del total_skills_points[player_one]
- return some_dict
- data = input()
- my_dict = {}
- total_skills_points = {}
- while not data == 'Season end':
- if ' -> ' in data:
- details = data.split(" -> ")
- player = details[0]
- position = details[1]
- skill_points = int(details[2])
- if player not in my_dict.keys():
- my_dict[player] = {position: skill_points}
- else:
- if position not in my_dict[player]:
- my_dict[player].update({position: skill_points})
- else:
- old_score = my_dict[player][position]
- my_dict[player].update({position: max(skill_points, old_score)})
- elif ' vs ' in data:
- details = data.split(' vs ')
- player1 = details[0]
- player2 = details[1]
- if is_players_valid(my_dict, player1, player2):
- my_dict = time_for_duel(my_dict, player1, player2)
- total_skills_points = (calculate_total_skill_points(my_dict))
- data = input()
- for name, points in sorted(total_skills_points.items(), key=lambda kv: (-kv[1], kv[0])):
- print(f'{name}: {points} skill')
- for name1, points1 in sorted(my_dict[name].items(), key=lambda kv: (-kv[1], kv[0])):
- print(f'- {name1} <::> {points1}')
- ################################################################################################################
- # 04. Snow White
- items = input()
- my_dwarfs = {}
- hat_colors = {}
- while not items == "Once upon a time":
- details = items.split(" <:> ")
- name = details[0]
- color = details[1]
- physics = int(details[2])
- id = name + ":" + color
- if id not in my_dwarfs:
- if color not in hat_colors:
- hat_colors[color] = 1
- else:
- hat_colors[color] += 1
- my_dwarfs[id] = [0, color]
- my_dwarfs[id][0] = max([my_dwarfs[id][0], physics])
- items = input()
- sorted_dwrafs = dict(sorted(my_dwarfs.items(), key=lambda x: (x[1][0], hat_colors[x[1][1]]), reverse=True))
- for key, value in sorted_dwrafs.items():
- details = key.split(":")
- print(f"({details[1]}) {details[0]} <-> {value[0]}")
- ################################################################################################################
- # 05. Dragon Army
- n_dragons = int(input())
- my_dragons = {}
- for _ in range(n_dragons):
- details = input().split()
- color_type = details[0]
- name = details[1]
- if not name[0].isupper():
- continue
- damage = details[2]
- if damage == 'null':
- damage = 45
- else:
- damage = int(damage)
- health = details[3]
- if health == 'null':
- health = 250
- else:
- health = int(health)
- armor = details[4]
- if armor == 'null':
- armor = 10
- else:
- armor = int(armor)
- if color_type not in my_dragons:
- my_dragons[color_type] = {name: [damage, health, armor]}
- else:
- if name not in my_dragons[color_type]:
- my_dragons[color_type].update({name: [damage, health, armor]})
- else:
- my_dragons[color_type].update({name: [damage, health, armor]})
- for key, value in my_dragons.items():
- average_sum = [0, 0, 0]
- for dragon, stats in value.items():
- for index, el in enumerate(stats):
- average_sum[index] += el / len(value)
- print(key, end="::")
- result = ('/'.join([f"{el:.2f}" for el in average_sum]))
- print(f"({result})")
- for dragon1, stats1 in sorted(value.items(), key=lambda x: x[0]):
- result = f"-{dragon1} -> damage: {stats1[0]}, health: {stats1[1]}, armor: {stats1[2]}"
- print(result)
- ################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement