Programming contests

ECN selejtező programozó csapatverseny, 2018. április 21.

April 21, 2018 10:15 AM – April 21, 2018 3:15 PM

Anagram Groups

World-renowned Prof. A. N. Agram's current research deals with large anagram groups. He has just found a new application for his theory on the distribution of characters in English language texts. Given such a text, you are to find the largest anagram groups.

A text is a sequence of words. A word w is an anagram of a word v if and only if there is some permutation p of character positions that takes w to v. Then, w and v are in the same anagram group. The size of an anagram group is the number of words in that group. Find the 5 largest anagram groups.

Input Specification

The input contains words composed of lowercase alphabetic characters (one word in each line). It is terminated by end-of-file (EOF).

Output Specification

Output the 5 largest anagram groups. If there are less than 5 groups, output them all. Sort the groups by decreasing size. Break ties lexicographically by the lexicographically smallest element. For each group output, print its size and its member words (separate each word using a space). Sort the member words lexicographically and print equal words only once. See the sample output below for exact formatting.

Sample Input

  1. undisplayed
  2. trace
  3. tea
  4. singleton
  5. eta
  6. eat
  7. displayed
  8. crate
  9. cater
  10. carte
  11. caret
  12. beta
  13. beat
  14. bate
  15. ate
  16. abet
download as text file

Output for Sample Input

  1. Group of size 5: caret carte cater crate trace
  2. Group of size 4: abet bate beat beta
  3. Group of size 4: ate eat eta tea
  4. Group of size 1: displayed
  5. Group of size 1: singleton
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019