Problem S. 7. (March 2005)
S. 7. Given a set of words, each of length between 5 and 30 letters. Write a program to sort them such that the last 5 letters of each word matches the first 5 letters of the next one. The number of words is at most 10,000 and only the 26 lower case letters of the English alphabet are used.
The first line of the input contains the number of words; then each subsequent line contains one word. If there exists a proper sorting, write one to the output such that each line contains one word. If there is no solution, just display NO SOLUTION.
Deadline expired on 15 April 2005.