The government publishes a list of the 10,000 most popular baby names along with their frequency each year (the number of babies with that name). This only has a problem with some names having different spellings. For instance, even if "John" and ".Jon" have almost the same name, they are included individually in the list. Write an algorithm to print a new list of the true frequencies of each name from two lists: one of names/frequencies and the other of pairings of equivalent names. Be aware that John and Johnny are synonyms if John and Jon are as well as Jon and Johnny. (It is symmetric and transitive.) Any name may be used as the "actual" name on the final list. EXAMPLE Input: Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19) Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher) Output: John (27), Kris (36)
The government publishes a list of the 10,000 most popular baby names along with their frequency each year (the number of babies with that name). This only has a problem with some names having different spellings. For instance, even if "John" and ".Jon" have almost the same name, they are included individually in the list. Write an
EXAMPLE
Input:
Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19)
Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher)
Output: John (27), Kris (36)
Step by step
Solved in 2 steps