Colorful Parrots
InterviewTime limit1sMemory limit1024 MB
Given the body and tail colors of two parrots, list every distinct body and tail color pair a chick can have, sorted in dictionary order.
- Level
Easy2 of 10
- Topics
- Implementation, Sorting, Hash map
- Solved
- No attempts yet
Problem
Jaehyeon keeps two parrots, Popo and Lemon, and they have had many chicks over the years. While watching the parrots born to them, Jaehyeon noticed a simple rule about their colors. The body color of a chick is one of the father's body color, the father's tail color, the mother's body color, or the mother's tail color. The tail color of a chick is also one of these four colors.
Given the body color and tail color of the father, and the body color and tail color of the mother, print every possible pair of body color and tail color of a chick in dictionary order. (Do not print duplicate pairs of body color and tail color.)
Input
The first line contains the body color and tail color of the father parrot.
The second line contains the body color and tail color of the mother parrot.
Each color is a string of lowercase English letters with a length from to . The same color may appear more than once.
Output
Print the possible pairs of chick body color and tail color, one pair per line, in dictionary order. Dictionary order means that pairs are sorted by body color first, and pairs with the same body color are sorted by tail color.