Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python-Advanced-Exercises Tuples and Sets - Exercise
- # https://judge.softuni.org/Contests/Practice/Index/1833#0
- # 01. Unique Usernames
- # 02. Sets of Elements
- # 03. Periodic Table
- # 04. Count Symbols
- # 05. Longest Intersection
- # 06. Battle of Names
- ====================================================================================================
- # 01. Unique Usernames
- n = int(input())
- name_collection = set()
- for _ in range(n):
- name = input()
- name_collection.add(name)
- print(*name_collection, sep='\n')
- ====================================================================================================
- # 02. Sets of Elements
- data = input().split(' ')
- n = int(data[0])
- m = int(data[1])
- n_set = set()
- m_set = set()
- for _ in range(n):
- number = int(input())
- n_set.add(number)
- for _ in range(m):
- number = int(input())
- m_set.add(number)
- result = n_set.intersection(m_set)
- print(*result, sep='\n')
- ====================================================================================================
- # 03. Periodic Table
- n = int(input())
- collection = set()
- for _ in range(n):
- element = input().split(' ')
- for sub_el in element:
- collection.add(sub_el)
- print(*collection, sep='\n')
- ====================================================================================================
- # 04. Count Symbols
- text = input()
- letter_dict = {}
- for letter in text:
- if letter not in letter_dict:
- letter_dict[letter] = 0
- letter_dict[letter] += 1
- for data in sorted(letter_dict.items()):
- print(f'{data[0]}: {data[1]} time/s')
- ====================================================================================================
- # 05. Longest Intersection
- n = int(input())
- intersections = []
- for _ in range(n):
- data = input().split('-')
- data1 = data[0].split(',')
- data2 = data[1].split(',')
- first_start = int(data1[0])
- first_end = int(data1[1])
- second_start = int(data2[0])
- second_end = int(data2[1])
- set1 = set()
- set2 = set()
- for num in range(first_start, first_end + 1):
- set1.add(num)
- for num in range(second_start, second_end + 1):
- set2.add(num)
- result = set1.intersection(set2)
- intersections.append(result)
- max_len = 0
- position = -1
- for index, el in enumerate(intersections):
- if len(el) > max_len:
- max_len = len(el)
- position = index
- longest_intersection = list(sorted(intersections[position]))
- print(f'Longest intersection is [{", ".join([str(x) for x in longest_intersection])}] with length {max_len}')
- ====================================================================================================
- # 06. Battle of Names
- n = int(input())
- odd_set = set()
- even_set = set()
- for row in range(1, n + 1):
- name = input()
- ascii_sum = 0
- for ch in name:
- ascii_sum += ord(ch)
- ascii_sum = ascii_sum / row
- if not int(ascii_sum) % 2 == 0:
- odd_set.add(int(ascii_sum))
- else:
- even_set.add(int(ascii_sum))
- odd_sum = sum(odd_set)
- even_sum = sum(even_set)
- if odd_sum == even_sum:
- result = odd_set | even_set
- elif odd_sum > even_sum:
- result = odd_set - even_set
- elif even_sum > odd_sum:
- result = even_set ^ odd_set
- print(*result, sep=', ')
- ====================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement