Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 05. Programming Fundamentals Final Exam 300/300
- # https://judge.softuni.org/Contests/Practice/Index/2302#0
- #
- # 01. Activation Keys
- # 02. Emoji Detector
- # 03. P!rates
- ***************************************************************************************************
- # 01. Activation Keys
- key = input()
- command = input()
- while not command == 'Generate':
- command = command.split(">>>")
- if command[0] == 'Contains':
- substring = command[1]
- if substring in key:
- print(f"{key} contains {substring}")
- else:
- print("Substring not found!")
- command = input()
- continue
- elif command[0] == 'Flip':
- move = command[1]
- start_flip = int(command[2])
- end_flip = int(command[3])
- if move == 'Upper':
- key = key[:start_flip] + key[start_flip:end_flip].upper() + key[end_flip:]
- elif move == "Lower":
- key = key[:start_flip] + key[start_flip:end_flip].lower() + key[end_flip:]
- elif command[0] == 'Slice':
- start_slice = int(command[1])
- end_slice = int(command[2])
- key = key[:start_slice] + key[end_slice:]
- print(key)
- command = input()
- print(f"Your activation key is: {key}")
- ***************************************************************************************************
- # 02. Emoji Detector
- import re
- regex_pattern1 = r'([:]{2}|[*]{2})([A-Z]{1}[a-z]{2,})(\1)'
- data = input()
- matches = re.findall(regex_pattern1, data)
- threshold = 1
- for char in data:
- if char.isdigit():
- threshold *= int(char)
- cool_emojis = []
- for emoji in matches:
- coolness = 0
- for char in emoji[1]:
- coolness += ord(char)
- if coolness > threshold:
- cool_emojis.append(emoji)
- print(f'Cool threshold: {threshold}')
- if len(matches):
- print(f'{len(matches)} emojis found in the text. The cool ones are:')
- for result in cool_emojis:
- print(''.join(result))
- ***************************************************************************************************
- # 03. P!rates
- command = input()
- data = {}
- while not command == 'End':
- if "||" in command:
- command = command.split("||")
- city = command[0]
- population = int(command[1])
- gold = int(command[2])
- if city not in data:
- data[city] = [population] + [gold]
- else:
- data[city][0] += population
- data[city][1] += gold
- else:
- command = command.split("=>")
- if command[0] == 'Plunder':
- town = command[1]
- people = int(command[2])
- gold_stolen = int(command[3])
- if town in data:
- data[town][0] -= people
- data[town][1] -= gold_stolen
- print(f"{town} plundered! {gold_stolen} gold stolen, {people} citizens killed.")
- if data[town][0] == 0 or data[town][1] == 0:
- del data[town]
- print(f"{town} has been wiped off the map!")
- elif command[0] == 'Prosper':
- town = command[1]
- gold_added = int(command[2])
- if gold_added < 0:
- print(f"Gold added cannot be a negative number!")
- else:
- data[town][1] += gold_added
- print(f"{gold_added} gold added to the city treasury. {town} now has {data[town][1]} gold.")
- command = input()
- if len(data) <= 0:
- print("Ahoy, Captain! All targets have been plundered and destroyed!")
- else:
- print(f"Ahoy, Captain! There are {len(data)} wealthy settlements to go to:")
- for key, value in data.items():
- print(f"{key} -> Population: {value[0]} citizens, Gold: {value[1]} kg")
- ***************************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement