Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago