1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Karolina [17]
3 years ago
5

Write a C++ program that searches for anagrams in a dictionary. An anagram is a word obtained by scrambling the letters of some

string.
Computers and Technology
1 answer:
Semmy [17]3 years ago
8 0

Answer:

d, avt, car, feet, more, pitch, rome, tac, teef,

Anagrams of b in dictionary

Anagrams of cat in dictionary

avt, cat, tac,

Anagrams of room in dictionary

more, rome,

Anagrams of hello in dictionary

Anagrams of  in dictionary

Explanation:

// FindAnagrams.cpp : it is the starting point of application console.

//

#include <vector>

#include <hash_map>

#include <iostream>

#include <string>

#include <algorithm>

#include <map>

#include <set>

using namespace std;

using namespace stdext;

bool IsAnagrams(string& strA, string& strB)

{

   list<char> listA(strA.begin(), strA.end());

   list<char> listB(strB.begin(), strB.end());

   listA.sort();

   listB.sort();

   return listA == listB;

   // return equal(listA.begin(), listA.end(), listB.begin());

}

string SortChars(string str)

{

   list<char> l(str.begin(), str.end());

   l.sort();

   return string(l.begin(), l.end());

}

set<string> FindAnagrams(list<string>& dict, string findStr)

{

   map<string, set<string>> d;

   typedef pair<string, set<string>> MyPair;

   for(list<string>::const_iterator it = dict.begin(); it != dict.end(); ++it){

       string str(SortChars(*it));

       if(d.find(str) == d.end()){

           set<string> s;

           s.insert(*it);

           d.insert(MyPair(str, s));

       }

       else{

           d[str].insert(*it);

       }

   }

   string sortedStr(SortChars(findStr));

   return d[sortedStr];

}

int main(int argc, char* argv[])

{

   list<string> dict;

   dict.push_back("c");

   dict.push_back("car");

   dict.push_back("avt");

   dict.push_back("taac");

   dict.push_back("feet");

   dict.push_back("teef");

   dict.push_back("rom");

   dict.push_back("more");

   dict.push_back("pit");

   dict.sort();

   cout << "The dictionary: " << endl;

   copy(dict.begin(), dict.end(), ostream_iterator<string>(cout, ", "));

   cout << endl;

   list<string> testCases;

   testCases.push_back("d");

   testCases.push_back("car");

   testCases.push_back("rome");

   testCases.push_back("hell");

   testCases.push_back("");

   for(list<string>::iterator it = testCases.begin(); it != testCases.end(); ++it)

   {

       cout << endl << "Anagrams of " << *it << " in dictionary" << endl;

       set<string> output = FindAnagrams(dict, *it);

       copy(output.begin(), output.end(), ostream_iterator<string>(cout, ", "));

       cout << endl;

   }

   return 0;

}

You might be interested in
Which of these can expose a computer to a virus? Check all that apply.
Rina8888 [55]

Answer:

downloads, websites, emails?

4 0
2 years ago
Read 2 more answers
For this exercise, you are going to create a part of an Animal hierarchy. Unlike some of our examples and the previous exercises
kati45 [8]

Answer:

vehicle super class 9.1.4

Explanation:

So you need to create a super class containig all the animals use the class above for referance

5 0
2 years ago
1 punto
masya89 [10]

Answer:

Retailing.

Explanation:

La venta al por menor o retailing es el suministro de bienes físicos a los consumidores para uso personal, sea en pequeña o grandes cantidades, siempre que esté destinado a consumidores finales. Es un sector que consta de diferentes ramas (como la industria alimentaria, la industria de la moda, la industria del mobiliario para el hogar, etc.). El comercio minorista es el último eslabón de la cadena de suministro que va desde el fabricante hasta el consumidor.

4 0
3 years ago
What are color highlights?
SVETLANKA909090 [29]

A- overusing highlights lowers the contrast and degrads the effect of the highlights.

3 0
3 years ago
Read 2 more answers
Use these sentence starters to explain how Cat Insanity is an analogy for debt repayment.
denpristay [2]

Answer: Can Insanity is like a debt repayment, if you don't pay or feed it on time they will die/ interest rate of the bank will be more and more expensive.

Explanation:

7 0
2 years ago
Other questions:
  • Susan will be configuring a snort network ids sensor to monitor her subnetwork. she will be using a web-based console interface
    8·1 answer
  • When uninstalling software, it is best to delete the folder containing the software?
    11·1 answer
  • How is sharepoint used in organization today?
    12·1 answer
  • zeroIt is a function that takes one argument and returns no value. The function stores the value 0 back into the parameter. x is
    8·1 answer
  • The main devices in a rectifier are:
    14·2 answers
  • What feature of a word processing program helps you to easily check and correct spelling mistakes?
    9·1 answer
  • Network Architecture and Topology: Mastery Test
    15·1 answer
  • What does a page break do?
    13·1 answer
  • In a paragraph, describe in detail a practical real-world example of where you would implement a singly-linked list and why a si
    8·1 answer
  • What is the first phone ever made?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!