DMOPC '15 Contest 4 P1 - Dictionary

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

As a studious French officer, Pierre-François Bouchard is interested in ancient languages. In a recent expedition, he uncovered a clay tablet with what appeared to be inscriptions in a long-forgotten language. Having made a copy of all the words on the tablet, Pierre-François would like to create a dictionary for future scholars. He's transcribed N words from the tablet, and has contacted you in the hopes that you'll be able to sort them for him.

Each word is formed only from lowercase Latin characters no longer than 20 characters in length. You are to organize the words into alphabetical sections by the first letter, with individual sections sorted in lexicographically increasing order.

Remember:

A string S is said to be lexicographically smaller than a string T if |S| < |T| and S is a prefix of T or S_k < T_k and S_i = T_i (0 \le i < k, 0 \le k < \min(|S|, |T|)). Here, |X| denotes the length of the string.

Input Specification

The first line of input will contain the number N (1 \le N \le 10).

The following N lines each contain a word.

Output Specification

For each non-empty section, output a line containing all words in lexicographical order separated by (a comma and space).

Sample Input

5
eggnog
cake
biscuits
chocolate
tea

Sample Output

biscuits
cake, chocolate
eggnog
tea

Comments

There are no comments at the moment.