#C13441. Generate Lexicographical Word Pairs
Generate Lexicographical Word Pairs
Generate Lexicographical Word Pairs
You are given a list of words. Your task is to remove any duplicates and then generate all unique pairs of words \( (a, b) \) such that \( a \) comes before \( b \) in lexicographical order (i.e., \( a < b \)).
The resulting pairs should be listed in lexicographical order. If no valid pair exists (i.e. when the list contains less than two unique words), no output should be produced.
Note: Each pair should be printed on a new line in the format: word1 word2
.
inputFormat
The first line contains an integer \( n \) (\( n \geq 1 \)), representing the number of words. The second line contains \( n \) space-separated words.
outputFormat
For each valid pair \( (a, b) \) such that \( a < b \) in lexicographical order, output a single line with the two words separated by a space. If no valid pair exists, output nothing.
## sample3
apple banana cherry
apple banana
apple cherry
banana cherry
</p>