Question: In this problem you will write a program to recognize all anagrams in a list of words ( strings of letters ) . Two words

In this problem you will write a program to recognize all anagrams in a list of words
(strings of letters). Two words are anagrams of each other if one can be formed by
rearranging the letters in the other. For example, the following two words are anagrams
of each other:
TOMMARVOLORIDDLE
IAMLORDVOLDEMORT
To easily recognize if two words w1 and w2 are anagrams, one can simply sort all the
letters of both words into alphabetical order. The two words are the same if and only
if the sorted strings are the same. The sorted string is called a signature of a word,
because all words that are the same(in this context) have the same signature. For
example, the signature of the strings above is:
2
ADDEILLMMOOORRTV
(a) Write the function
string signature(const string& w);
which computes the signature of the string w.
(b) Write a program that reads in a list of words consisting of upper case letters, and
prints out all the anagrams. Use a map that uses the signature as the index, and
stores a vector of strings as the data. All input words with the same signature
will be stored in the same vector. For each signature, the program should print all
input words that have the same signature on a single line. You may assume that
all words consist only of upper case letters. Read until the end of file is reached.
Write your program in prob2.cc.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!