Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dictionaries - Exercise Python Fundamentals 100/100
- # https://judge.softuni.org/Contests/Compete/Index/1737#0
- *************************************************************************************************
- # 01. Count Chars in a String
- data = input()
- new_data = data.replace(" ", "")
- data = new_data
- my_dict = {}
- for word in data:
- for letter in word:
- if letter not in my_dict:
- my_dict[letter] = 1
- else:
- my_dict[letter] += 1
- for el in my_dict:
- print(f'{el} -> {my_dict[el]}')
- *************************************************************************************************
- # 02. A Miner Task
- data = input()
- miner = {}
- while not data == 'stop':
- resource = data
- count = int(input())
- if resource not in miner:
- miner[resource] = 0
- miner[resource] += count
- data = input()
- for el in miner:
- print(f'{el} -> {miner[el]}')
- *************************************************************************************************
- # 03. Capitals
- # 1. zip
- country = input().split(', ')
- capitals = input().split(', ')
- my_dict = {}
- my_dict = dict(zip(country, capitals))
- for el in my_dict:
- print(f"{el} -> {my_dict[el]}")
- #2. without zip
- country = input().split(', ')
- capitals = input().split(', ')
- for index, el in enumerate(country):
- my_dict = {}
- my_dict[el] = capitals[index]
- print(f"{el} -> {my_dict[el]}")
- *************************************************************************************************
- # 04. Phonebook
- data = input()
- contacts = {}
- while not len(data) == 1:
- data = data.split("-")
- key = data[0]
- value = data[1]
- if key not in contacts:
- contacts[key] = value
- else:
- contacts[key] = value
- data = input()
- n = int(data)
- for name in range(n):
- searched_name = input()
- if searched_name in contacts:
- print(f'{searched_name} -> {contacts[searched_name]}')
- else:
- print(f"Contact {searched_name} does not exist.")
- *************************************************************************************************
- # 05. Legendary Farming
- materials = input()
- legendary = {'shards': 'Shadowmourne', 'fragments': 'Valanyr', 'motes': 'Dragonwrath'}
- key_materials = {'shards': 0, 'fragments': 0, 'motes': 0}
- junk = {}
- obtained = False
- final_print = ""
- while not obtained:
- details = materials.split(' ')
- for index in range(0, len(details), 2):
- amount = int(details[index])
- material = details[index + 1].lower()
- if material in legendary.keys():
- key_materials[material] += amount
- if key_materials[material] >= 250:
- key_materials[material] -= 250
- final_print = legendary[material]
- obtained = True
- print(f'{final_print} obtained!')
- break
- else:
- if material not in junk.keys():
- junk[material] = 0
- junk[material] += amount
- if not obtained:
- materials = input()
- for key, value in key_materials.items():
- print(f'{key}: {value}')
- for key, value in junk.items():
- print(f'{key}: {value}')
- *************************************************************************************************
- # 06. Orders
- data = input()
- products = {}
- while not data == 'buy':
- data = data.split()
- key = data[0]
- amount = data[1]
- value = data[2]
- if key not in products:
- products[key] = []
- else:
- if products[key][0] != amount:
- products[key][0] = amount
- products[key][1] = float(value) + float(products[key][1])
- if amount not in products[key]:
- products[key].append(amount)
- if value not in products[key]:
- products[key].append(value)
- data = input()
- for el in products:
- print(f'{el} -> {float(products[el][0]) * float(products[el][1]):.2f}')
- *************************************************************************************************
- # 07. SoftUni Parking
- n = int(input())
- registry = {}
- for client in range(n):
- data = input()
- data = data.split()
- action = data[0]
- if action == 'register':
- name = data[1]
- code = data[2]
- if name not in registry:
- registry[name] = code
- print(f"{name} registered {code} successfully")
- else:
- print(f"ERROR: already registered with plate number {code}")
- elif action == 'unregister':
- name = data[1]
- if name not in registry:
- print(f"ERROR: user {name} not found")
- else:
- print(f"{name} unregistered successfully")
- del registry[name]
- for el in registry:
- print(f'{el} => {registry[el]}')
- *************************************************************************************************
- # 08. Courses
- data = input()
- courses_dict = {}
- while not data == 'end':
- data = data.split(' : ')
- course = data[0]
- name = data[1]
- if course not in courses_dict:
- courses_dict[course] = [name]
- else:
- courses_dict[course].append(name)
- data = input()
- for el in courses_dict:
- print(f'{el}: {len(courses_dict[el])}')
- for name in courses_dict[el]:
- print(f'-- {name}')
- *************************************************************************************************
- # 09. Student Academy
- n = int(input())
- students = {}
- for _ in range(n):
- name = input()
- grade = float(input())
- if name not in students:
- students[name] = grade
- else:
- students[name] += grade
- students[name] /= 2
- for name in students:
- if students[name] >= 4.50:
- print(f'{name} -> {students[name]:.2f}')
- *************************************************************************************************
- # 10. Company Users
- data = input()
- company = {}
- while not data == 'End':
- data = data.split(" -> ")
- name = data[0]
- id = data[1]
- if name not in company:
- company[name] = [id]
- else:
- if id not in company[name]:
- company[name].append(id)
- data = input()
- for el in company:
- print(f'{el}')
- for name in company[el]:
- print(f'-- {name}')
- *************************************************************************************************
- # 11. Force Book *
- def force_user_exists(force_book_dict: dict, user: str):
- for user_list in force_book_dict.values():
- if user in user_list:
- return True
- return False
- def remove_user_from_side(force_book_dict: dict, user: str):
- for (side, users) in force_book_dict.items():
- if user in users:
- force_book_dict[side].remove(user)
- def initial_join_force_side(force_book_dict: dict, side: str, user: str):
- if side not in force_book_dict.keys() and not force_user_exists(force_book_dict, user):
- force_book_dict[side] = []
- force_book_dict[side].append(user)
- elif not force_user_exists(force_book_dict, user):
- force_book_dict[side].append(user)
- def join_force_side(force_book_dict: dict, side: str, user: str):
- if side not in force_book_dict.keys() and not force_user_exists(force_book_dict, user):
- force_book_dict[side] = []
- force_book_dict[side].append(user)
- elif not force_user_exists(force_book_dict, user):
- if side not in force_book_dict.keys():
- force_book_dict[side] = []
- force_book_dict[side].append(user)
- elif force_user_exists(force_book_dict, user):
- remove_user_from_side(force_book_dict, user)
- if side not in force_book_dict.keys():
- force_book_dict[side] = []
- force_book_dict[side].append(user)
- print(f'{user} joins the {side} side!')
- force_book = {}
- command = input()
- while command != 'Lumpawaroo':
- if '|' in command:
- details = command.split(' | ')
- force_side = details[0]
- force_user = details[1]
- initial_join_force_side(force_book, force_side, force_user)
- elif '->' in command:
- details = command.split(' -> ')
- force_user = details[0]
- force_side = details[1]
- join_force_side(force_book, force_side, force_user)
- command = input()
- for key, value in force_book.items():
- if len(value) > 0:
- print(f'Side: {key}, Members: {len(value)}')
- for el in value:
- print(f"! {el}")
- *************************************************************************************************
- # 12. SoftUni Exam Results *
- command = input()
- data = {}
- all_languages = []
- count_languages = []
- while not command == 'exam finished':
- command = command.split("-")
- if command[1] == "banned":
- name = command[0]
- del data[name]
- command = input()
- continue
- elif not command[1] == 'banned':
- name = command[0]
- language = command[1]
- points = int(command[2])
- if name not in data:
- data[name] = points
- else:
- if points > data[name]:
- data[name] = points
- all_languages += [language]
- if language not in count_languages:
- count_languages.append(language)
- command = input()
- print('Results:')
- for name, points in data.items():
- print(f'{name} | {points}')
- print('Submissions:')
- for subm in range(len(count_languages)):
- result = count_languages[subm]
- print(f"{count_languages[subm]} - {all_languages.count(result)}")
- *************************************************************************************************
Add Comment
Please, Sign In to add comment