Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the implementation of an autocorrect function given a search query string the function should return all words which are anagrams given 2 arrays words[n]

complete the implementation of an autocorrect function given a search query string the function should return all words which are anagrams given 2 arrays words[n] and queries[q] for each query return an array of the strings that are anagrams sorted alphabetically ascending. complete the function getSearchResults, which takes the following arguments: string words[n]: the list of words to search, string queries[q]: the words to search for returns string[q][]: the results for each search query #include using namespace std; string ltrim(const string &); string rtrim(const string &); /* * Complete the 'getSearchResults' function below. * * The function is expected to return a 2D_STRING_ARRAY. * The function accepts following parameters: * 1. STRING_ARRAY words * 2. STRING_ARRAY queries */ vector> getSearchResults(vector words, vector queries) { } int main() { ofstream fout(getenv("OUTPUT_PATH")); string words_count_temp; getline(cin, words_count_temp); int words_count = stoi(ltrim(rtrim(words_count_temp))); vector words(words_count); for (int i = 0; i < words_count; i++) { string words_item; getline(cin, words_item); words[i] = words_item; } string queries_count_temp; getline(cin, queries_count_temp); int queries_count = stoi(ltrim(rtrim(queries_count_temp))); vector queries(queries_count); for (int i = 0; i < queries_count; i++) { string queries_item; getline(cin, queries_item); queries[i] = queries_item; } vector> result = getSearchResults(words, queries); for (size_t i = 0; i < result.size(); i++) { for (size_t j = 0; j < result[i].size(); j++) { fout << result[i][j]; if (j != result[i].size() - 1) { fout << " "; } } if (i != result.size() - 1) { fout << " "; } } fout << " "; fout.close(); return 0; } string ltrim(const string &str) { string s(str); s.erase( s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) ); return s; } string rtrim(const string &str) { string s(str); s.erase( find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), s.end() ); return s; }

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

Artificial Intelligence Structures And Strategies For Complex Problem Solving

Authors: George Luger

6th Edition

0321545893, 9780321545893

More Books

Students also viewed these Algorithms questions