Advertisement
GeorgiLukanov87

05. Programming Fundamentals Final Exam 300/300

Jul 14th, 2022 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.83 KB | None | 0 0
  1. # 05. Programming Fundamentals Final Exam 300/300
  2. # https://judge.softuni.org/Contests/Practice/Index/2302#0
  3. #
  4. # 01. Activation Keys
  5. # 02. Emoji Detector
  6. # 03. P!rates
  7. ***************************************************************************************************
  8.  
  9. # 01. Activation Keys
  10.  
  11. key = input()
  12. command = input()
  13. while not command == 'Generate':
  14.     command = command.split(">>>")
  15.     if command[0] == 'Contains':
  16.         substring = command[1]
  17.         if substring in key:
  18.             print(f"{key} contains {substring}")
  19.         else:
  20.             print("Substring not found!")
  21.         command = input()
  22.         continue
  23.  
  24.     elif command[0] == 'Flip':
  25.         move = command[1]
  26.         start_flip = int(command[2])
  27.         end_flip = int(command[3])
  28.         if move == 'Upper':
  29.             key = key[:start_flip] + key[start_flip:end_flip].upper() + key[end_flip:]
  30.         elif move == "Lower":
  31.             key = key[:start_flip] + key[start_flip:end_flip].lower() + key[end_flip:]
  32.  
  33.     elif command[0] == 'Slice':
  34.         start_slice = int(command[1])
  35.         end_slice = int(command[2])
  36.         key = key[:start_slice] + key[end_slice:]
  37.  
  38.     print(key)
  39.     command = input()
  40.  
  41. print(f"Your activation key is: {key}")
  42.  
  43. ***************************************************************************************************
  44.  
  45. # 02. Emoji Detector
  46.  
  47. import re
  48.  
  49. regex_pattern1 = r'([:]{2}|[*]{2})([A-Z]{1}[a-z]{2,})(\1)'
  50. data = input()
  51. matches = re.findall(regex_pattern1, data)
  52.  
  53. threshold = 1
  54. for char in data:
  55.     if char.isdigit():
  56.         threshold *= int(char)
  57.  
  58. cool_emojis = []
  59. for emoji in matches:
  60.     coolness = 0
  61.     for char in emoji[1]:
  62.         coolness += ord(char)
  63.  
  64.     if coolness > threshold:
  65.         cool_emojis.append(emoji)
  66.  
  67. print(f'Cool threshold: {threshold}')
  68. if len(matches):
  69.     print(f'{len(matches)} emojis found in the text. The cool ones are:')
  70.     for result in cool_emojis:
  71.         print(''.join(result))
  72.  
  73. ***************************************************************************************************
  74.  
  75. # 03. P!rates
  76.  
  77. command = input()
  78. data = {}
  79.  
  80. while not command == 'End':
  81.     if "||" in command:
  82.         command = command.split("||")
  83.         city = command[0]
  84.         population = int(command[1])
  85.         gold = int(command[2])
  86.         if city not in data:
  87.             data[city] = [population] + [gold]
  88.         else:
  89.             data[city][0] += population
  90.             data[city][1] += gold
  91.     else:
  92.         command = command.split("=>")
  93.         if command[0] == 'Plunder':
  94.             town = command[1]
  95.             people = int(command[2])
  96.             gold_stolen = int(command[3])
  97.             if town in data:
  98.                 data[town][0] -= people
  99.                 data[town][1] -= gold_stolen
  100.                 print(f"{town} plundered! {gold_stolen} gold stolen, {people} citizens killed.")
  101.                 if data[town][0] == 0 or data[town][1] == 0:
  102.                     del data[town]
  103.                     print(f"{town} has been wiped off the map!")
  104.  
  105.         elif command[0] == 'Prosper':
  106.             town = command[1]
  107.             gold_added = int(command[2])
  108.             if gold_added < 0:
  109.                 print(f"Gold added cannot be a negative number!")
  110.             else:
  111.                 data[town][1] += gold_added
  112.                 print(f"{gold_added} gold added to the city treasury. {town} now has {data[town][1]} gold.")
  113.  
  114.     command = input()
  115.  
  116. if len(data) <= 0:
  117.     print("Ahoy, Captain! All targets have been plundered and destroyed!")
  118. else:
  119.     print(f"Ahoy, Captain! There are {len(data)} wealthy settlements to go to:")
  120.     for key, value in data.items():
  121.         print(f"{key} -> Population: {value[0]} citizens, Gold: {value[1]} kg")
  122.  
  123. ***************************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement