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
your friend's parent's are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
Lorico [155]

Answer:

A possible expense that are not a need are entertainment.

I hope this helped!

4 0
2 years ago
What is the importance of using Onedrive in Windows 10 and how knowledge of it will have an impact in today's workplace?
SashulF [63]

The importance of one drive in windows 10 is that it helps the user to synchronize files in their computer.

Onedrive is a cloud storage system that is useful for the storage of files in a secured manner. A person can easily access their files whenever they want to.

In todays workplace a knowledge of onedrive has a great impact because

  • Onedrive offers an unlimited access to files whenever they are needed
  • The files can be available and accessed from anywhere
  • It helps with the organization of files in the work place.

One drive allows for this to be done even when offline. When online, there is an automatic synchronization of the made changes.

Read more at brainly.com/question/17163678?referrer=searchResults

7 0
3 years ago
Read 2 more answers
Que es la felicidad??​
olchik [2.2K]
Se feliz el amor es nada
4 0
2 years ago
What was ARPANET?
Anit [1.1K]

Answer:

The ARPANET was the first network that provided commercial internet services. And also it was the first network to make use of the TCP/IP protocols. However, you need to know that the first ISP or the internet service provider was the Telenet, and it was the first commercial version of the ARPANET which was introduced in the year 1974. And this service started its service for the customers in the year 1989.

Explanation:

Please check the answer section.

7 0
3 years ago
Access time is:________.
worty [1.4K]

Answer:

B) the time it takes for the required sector to position itself under the read/write head.

Explanation:

In Computer science, Access time is the time it takes for the required sector to position itself under the read/write head. It is usually measured in milliseconds.

It is the speed of the storage device.

5 0
3 years ago
Other questions:
  • Prove that for every nfa with an arbitrary number of final states there is an equivalent nfa with only one final state. Can we m
    8·1 answer
  • A ____ database supports data distributed across several different sites.
    7·1 answer
  • What is ucspi-tcp pakage in qmail??
    5·1 answer
  • Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string
    8·1 answer
  • The array mycats is an 8 element array of type kitty that has already been declared and initialized. write the expression(s) in
    5·1 answer
  • Which software application offers a variety of templates for creating reports, flyers, and newsletters that you can access withi
    7·1 answer
  • In which area of the screen can features and functions of Word be accessed?
    9·2 answers
  • Chantelle wants to change the color scheme for her company's web app, and she needs to get the logos updated. What kind of devel
    8·1 answer
  • Why is computer called information processing machine ?????​
    6·2 answers
  • Computer always produces wrong output true or false<br>​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!