Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python-Advanced-Exercises , Tuples and Sets - Lab
- # https://judge.softuni.org/Contests/Practice/Index/1833#4
- # 01. Count Same Values
- # 02. Students' Grades
- # 03. Record Unique Names
- # 04. Parking Lot
- # 05. SoftUni Party
- # 06. Summation Pairs
- ========================================================================================================
- # 01. Count Same Values
- data = (float(x) for x in input().split(' '))
- nums_dict = {}
- for num in data:
- if num not in nums_dict:
- nums_dict[num] = 0
- nums_dict[num] += 1
- for kvp in nums_dict.items():
- print(f'{kvp[0]} - {kvp[1]} times')
- ========================================================================================================
- # 02. Students' Grades
- n = int(input())
- students = {}
- for _ in range(n):
- current_student = input().split(" ")
- name = current_student[0]
- grade = float(current_student[1])
- if name not in students:
- students[name] = []
- students[name].append(grade)
- for student in students.items():
- to_print = ' '.join(f"{x:.2f}" for x in student[1])
- average_grade = sum(student[1]) / len(student[1])
- print(f'{student[0]} -> {to_print} (avg: {average_grade:.2f})')
- ========================================================================================================
- # 03. Record Unique Names
- n = int(input())
- names_set_list = set()
- for _ in range(n):
- name = input()
- names_set_list.add(name)
- print(*names_set_list, sep='\n')
- ========================================================================================================
- # 04. Parking Lot
- n = int(input())
- parking_lot = set()
- for _ in range(n):
- details = input().split(', ')
- direction = details[0]
- car_number = details[1]
- if direction == 'IN':
- parking_lot.add(car_number)
- else:
- parking_lot.remove(car_number)
- if parking_lot:
- for car_num in parking_lot:
- print(car_num)
- else:
- print('Parking Lot is Empty')
- ========================================================================================================
- # 05. SoftUni Party
- n = int(input())
- regular_guests = set()
- vip_guests = set()
- for _ in range(n):
- reg_code = input()
- if reg_code[0].isdigit():
- vip_guests.add(reg_code)
- else:
- regular_guests.add(reg_code)
- guest_arrived = input()
- while not guest_arrived == 'END':
- current_guest = guest_arrived
- if current_guest[0].isdigit():
- if current_guest in vip_guests:
- vip_guests.remove(current_guest)
- elif current_guest in regular_guests:
- regular_guests.remove(current_guest)
- guest_arrived = input()
- print(len(vip_guests)+len(regular_guests))
- for name in sorted(vip_guests):
- print(name)
- for name in sorted(regular_guests):
- print(name)
- ========================================================================================================
- # 06. Summation Pairs
- from collections import deque
- numbers = deque([int(x) for x in input().split()])
- target_sum = int(input())
- unique_pairs = set()
- iterations = 0
- while numbers:
- first_num = numbers.popleft()
- for num in numbers:
- iterations += 1
- if (num + first_num) == target_sum:
- unique_pairs.add((first_num, num))
- print(f'{first_num} + {num} = {target_sum}')
- print(f'Iterations done: {iterations}')
- for pair in unique_pairs:
- print(pair)
- ========================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement