#K50247. Concatenation Pair Finder
Concatenation Pair Finder
Concatenation Pair Finder
You are given a list of distinct words and a target string. Your task is to determine if you can form the target string by concatenating exactly two distinct words from the list.
If a valid pair exists, print the two words separated by a single space. Otherwise, output No pair found
.
For example, if the list is ["apple", "banana", "carrot", "dog", "elephant"] and the target string is "carrotdog", the answer is "carrot dog".
Note: The concatenation should exactly match the target, and each of the two words must be different.
inputFormat
The input is read from stdin and has the following format:
N word1 word2 ... wordN target
Where:
N
is an integer representing the number of words.- The second line contains
N
space-separated words. - The third line contains the target string.
outputFormat
Print to stdout the two words separated by a single space that form the target string. If no such pair exists, print No pair found
.
5
apple banana carrot dog elephant
carrotdog
carrot dog