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
An administrative assistant types a document, saves, and prints. The assistant is using _____.
9966 [12]
The answer to your question is software. 
3 0
3 years ago
This type of program is designed to be transmitted over the internet and run in a web browser
vodomira [7]
This sounds like a web-based application because they are designed to be ran within a website, generally with Adobe Flash.
8 0
3 years ago
What college degrees did Steve Wozniak earn?
kap26 [50]
<span>University of California, Berkeley _ comp sci
De Anza College, _ comp sci</span>
7 0
3 years ago
PLEASE HELP!!!!!! ASAP
NNADVOKAT [17]

Answer:

use a wizard or use a design view

Explanation:

i took the test

4 0
3 years ago
Read 2 more answers
If I delete the emoji free app will I still have the emojis on my phone?
egoroff_w [7]
<span>If you delete the Emoji application from your phone there is a possibility the Emoji's will still hang around. It all depends on the way you set up the app on your phone. Some people opt to have settings and changes to the app saved on their SD card and some don't. If you save updates and changes to the app to your SD card you will still have remnants on your phone after deleting the app</span>
5 0
4 years ago
Read 2 more answers
Other questions:
  • While engineers work to create computers that can understand us emotionally, ________ are also evolving toward a more human appe
    12·1 answer
  • What is the answer please
    13·2 answers
  • Do you think social media should affect presidential elections
    6·2 answers
  • Imagine that you have configured the enable secret command, followed by the enable password command, from the console. You log o
    9·1 answer
  • You must keep track of some data. Your options are: (1) A linked-list maintained in sorted order. (2) A linked-list of unsorted
    5·1 answer
  • What happens if i unplug my alarm system?
    11·1 answer
  • Which of the following is NOT an example of one of the six primary ways businesses use the Internet?
    10·2 answers
  • What type of email communication reaches out to former clients and older prospects and encourages a reply? Strategic email Onboa
    5·1 answer
  • 1.1 what is the osi security architecture? 1.2 what is the difference between passive and active security threats? 1.3 list and
    5·1 answer
  • What is a use case of factorization in quantum computing?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!