Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 w and w 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 samein this context have the same signature. For
example, the signature of the strings above is:
ADDEILLMMOOORRTV
a Write the function
string signatureconst 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 probcc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started