#K34837. Group and Sort Strings
Group and Sort Strings
Group and Sort Strings
You are given a list of strings. Your task is to group the strings based on their lengths and then sort each group in lexicographical (dictionary) order. After sorting, print the strings so that each string is on its own line. Additionally, separate different groups (i.e. groups of strings having different lengths) with an empty line.
For example, if the input strings are:
apple bat carrot dog elephant ant
They are first grouped as follows:
- Length 3: bat, dog, ant (sorted becomes: ant, bat, dog)
- Length 5: apple
- Length 6: carrot
- Length 8: elephant
The final output should be:
ant bat dog
apple
carrot
elephant
inputFormat
The first line contains an integer n (0 ≤ n ≤ 10^5), the number of strings. Each of the following n lines contains a single non-empty string.
outputFormat
Output the grouped and sorted strings. Each string is printed on a separate line. Strings that are in different groups (i.e. have different lengths) are separated by an empty line.## sample
1
apple
apple