Feladat: S.7 Korcsoport: - Nehézségi fok: -
Füzet: 2005/március, 192. oldal  PDF  |  MathML 
Témakör(ök): Nehezebb feladat
Hivatkozás(ok):Feladatok: 2005/március: S.7

A szöveg csak Firefox böngészőben jelenik meg helyesen. Használja a fenti PDF file-ra mutató link-et a letöltésre.

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.