Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

60-141 Winter 2019 Assignment 2: Pointers and Strings Description Given some text input, you are to find the largest anagram groups. A text is a

60-141 Winter

2019 Assignment 2: Pointers and Strings

Description

Given some text input, 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

The input contains words composed of lowercase alphabetic characters, separated by whitespace(or new line). It is terminated by the word STOP. You can assume there will be no more than 100 words, and each word does not exceed 20 characters long.

Output

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 lexicographical smallest element. For each group output, print its size and its member words. Sort the member words lexicographically and print equal words only once.

Sample Input

undisplayed

trace

tea

singleton

eta

eat

displayed

crate

cater

carte

caret

beta

beat

bate

ate

abet

STOP

Sample Output

Group of size 5: caret carte cater crate trace

Group of size 4: abet bate beat beta

Group of size 4: ate eat eta tea

Group of size 1: displayed

Group of size 1: singleton

using C language

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started