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
I need help picture above
sammy [17]

Answer:

True

Explanation:

hoped I helped Im Eve btw Have a great day and consider marking this brainliest if you do thank you in advanced!

6 0
3 years ago
Read 2 more answers
Select the correct line of missing code to create an output of "hello."
s2008m [1.1K]

Answer:

B

Explanation:

This feels like an error on the question issuer's part.

3 0
2 years ago
Merge sort has a o(n log2(n)) complexity. if a computer can sort 1,024 elements in an amount of time x, approximately how long w
Musya8 [376]
<span>1,048,576 is 1,024 times 1,024, 1,024 * 1,024 or 1,024 squared or 1,024^2. If a computer takes x amount of time to sort 1,024 elements then the relationship is a 1 to 1. Therefore the computer will take x times x or x^2 (x squared) amount of time to sort 1,048,576.</span>
6 0
3 years ago
What are two great ways to find clues to locate commands on the ribbon?
Lapatulllka [165]

Solution:

Look at the tabs and hover over images. are two great ways to find clues to locate commands on the ribbon.

There are six main categories for command which are; one-click, toggle, split buttons, drop-down and tick box.  Categories can be mixed so it is useful to understand the basics to develop the Excel skills.

The ribbon is a user interface element created by Microsoft, which was introduced with Microsoft Office 2007. It is part of the "Microsoft Office Fluent" interface and combines the menu bar and toolbar into a single floating pane. By default, it is located at the top of the screen in Office applications, such as Access, Excel, PowerPoint, Word, and Outlook.

This is the required solution.


6 0
3 years ago
Cual es la definición de grouded ​
pochemuha

Answer:

ben bilanciato e reattivo.

(di un pilota o di un aeromobile) vietato o impedito di volare.

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • Which of these definitions BEST explains what plagiarism is:
    14·2 answers
  • Exit network systems, information support, and software development are all careers in which career cluster?
    10·1 answer
  • What are the 6 external parts of a computer system
    8·1 answer
  • Which two statements are true regarding the user exec mode? (choose two.)?
    6·1 answer
  • What software development model focuses on improving the product in small steps each time through the cycle?
    14·2 answers
  • In the Dynamic Partitioning technique of memory management, the placement algorithm that scans memory from the location of the l
    11·1 answer
  • If nothings faster than light then how do the dark get there first????
    5·2 answers
  • A certain manager makes the following statement "Our internet company is in business for the money, making profits, and making t
    13·1 answer
  • What are 25 items that trees made?
    6·2 answers
  • What are some other ways to program a robot to navigate a complicated environment other than straight paths and right angle (90
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!