project_python.3.2/lesson.4.py

53 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

''' ****** Задание 4 из 20 *********
* Напишите программу, которая определит, сколько учеников любят обе каши.
Формат ввода
В первых двух строках указывается количество детей, любящих манную и овсяную каши (N и M).
Затем идут N строк — фамилии детей, которые любят манную кашу, и M строк с фамилиями детей, любящих овсяную кашу.
Гарантируется, что в группе нет однофамильцев.
Формат вывода
Количество учеников, которые любят обе каши.
Если таких не окажется, в строке вывода нужно написать «Таких нет».
Подсказка
Считайте два множества фамилий и вычислите их пересечение.
Пример 1
Ввод
3
2
Васильев
Петров
Васечкин
Иванов
Михайлов
Вывод
Таких нет
'''
if __name__ == "__main__":
num_children_who_like_semolina = int(input())
num_children_who_like_oatmeal = int(input())
children_who_like_semolina = set()
children_who_like_oatmeal = set()
for child_index in range(num_children_who_like_semolina):
child_name = input()
children_who_like_semolina.add(child_name)
for child_index in range(num_children_who_like_oatmeal):
child_name = input()
children_who_like_oatmeal.add(child_name)
children_who_like_both = children_who_like_semolina & children_who_like_oatmeal
count_who_like_both = len(children_who_like_both)
print(count_who_like_both if count_who_like_both else 'Таких нет')