craig burgler
BAN USER
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Here is a Python solution. The input format is the name of the person we want to inquire about on the first line followed by any number of lines each containing a "<son> <father>" pair.
person = input()
father_of = {}
father_son_pair = input().split()
while father_son_pair:
father_of[father_son_pair[0]] = father_son_pair[1]
father_son_pair = input().split()
num_grandchildren = 0
for son, father in father_of.items():
if person == father:
num_grandchildren += list(father_of.values()).count(son)
print(num_grandchildren)
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{person = input()
father_of = {}
father_son_pair = input().split()
while father_son_pair:
father_of[father_son_pair[0]] = father_son_pair[1]
father_son_pair = input().split()
num_grandchildren = 0
for son, father in father_of.items():
if person == father:
num_grandchildren += list(father_of.values()).count(son)
print(num_grandchildren)
Here is a Python solution. The input format is the name of the person we want to inquire about on the first line followed by any number of lines each containing a "<son> <father>" pair.
-
craig burgler
June 23, 2016 | Flag
Reply
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Here is a Python solution. The input format is the name of the person we want to inquire about on the first line followed by any number of lines each containing a "<son> <father>" pair.
- craig burgler June 23, 2016