Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 04. Programming Fundamentals Final Exam 300/300
- # https://judge.softuni.org/Contests/Practice/Index/2303#0
- #
- # 01. Password Reset
- # 02. Fancy Barcodes
- # 03. Heroes of Code and Logic VI
- ==============================================================================================
- # 01. Password Reset
- password = input()
- command = input()
- while not command == 'Done':
- raw_password = ""
- command = command.split()
- if command[0] == 'TakeOdd':
- for odd_indx in range(len(password)):
- if odd_indx % 2 != 0:
- raw_password += password[odd_indx]
- password = raw_password
- elif command[0] == 'Cut':
- index = int(command[1])
- length = int(command[2])
- password = password[:index] + password[index+length:]
- elif command[0] == 'Substitute':
- substring = command[1]
- substitute = command[2]
- if substring in password:
- password = password.replace(substring, substitute)
- else:
- print("Nothing to replace!")
- command = input()
- continue
- print(password)
- command = input()
- print(f"Your password is: {password}")
- ==============================================================================================
- # 02. Fancy Barcodes
- import re
- def calculate_sum(some_string: str):
- sum_of_digits = ""
- for char in some_string:
- if char.isdigit():
- sum_of_digits += char
- if len(sum_of_digits) > 0:
- return sum_of_digits
- return "00"
- n = int(input())
- pattern = r'(\@)(\#+)([A-Z][A-Za-z0-9]{4,}[A-Z])(\@)(\#+)'
- for b_code in range(n):
- data = input()
- valid_data = re.findall(pattern, data)
- if len(valid_data) == 0:
- print('Invalid barcode')
- else:
- for el in valid_data:
- current_word = el[2]
- final_result = calculate_sum(current_word)
- print(f'Product group: {final_result}')
- ==============================================================================================
- # 03. Heroes of Code and Logic VI
- n_heroes = int(input())
- heroes = {}
- command = input()
- for _ in range(n_heroes):
- command = command.split()
- name = command[0]
- hp = int(command[1])
- mp = int(command[2])
- if name not in heroes:
- heroes[name] = [hp] + [mp]
- else:
- heroes[name] += hp
- heroes[name] += mp
- command = input()
- while not command == 'End':
- command = command.split(' - ')
- if command[0] == 'CastSpell':
- name = command[1]
- mp_needed = int(command[2])
- spell_name = command[3]
- if heroes[name][1] >= mp_needed:
- heroes[name][1] -= mp_needed
- print(f"{name} has successfully cast {spell_name} and now has {heroes[name][1]} MP!")
- else:
- print(f"{name} does not have enough MP to cast {spell_name}!")
- elif command[0] == 'TakeDamage':
- name = command[1]
- damage = int(command[2])
- attacker = command[3]
- heroes[name][0] -= damage
- if heroes[name][0] > 0:
- print(f'{name} was hit for {damage} HP by {attacker} and now has {heroes[name][0]} HP left!')
- else:
- print(f"{name} has been killed by {attacker}!")
- del heroes[name]
- elif command[0] == 'Recharge':
- name = command[1]
- amount = int(command[2])
- temp_mana = heroes[name][1]
- if temp_mana + amount >= 200:
- heroes[name][1] = 200
- print(f"{name} recharged for {200-temp_mana} MP!")
- else:
- heroes[name][1] += amount
- print(f"{name} recharged for {amount} MP!")
- elif command[0] == 'Heal':
- name = command[1]
- amount = int(command[2])
- temp_health = heroes[name][0]
- if temp_health + amount >= 100:
- heroes[name][0] = 100
- print(f"{name} healed for {100 - temp_health} HP!")
- else:
- heroes[name][0] += amount
- print(f"{name} healed for {amount} HP!")
- command = input()
- for hero in heroes:
- print(hero)
- print(f' HP: {heroes[hero][0]}')
- print(f' MP: {heroes[hero][1]}')
- ==============================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement