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
masha68 [24]
3 years ago
11

You work on a team whose job is to understand the most sought after toys for the holiday season. A teammate of yours has built a

webcrawler that extracts a list of quotes about toys from different articles. You need to take these quotes and identify which toys are mentioned most frequently. Write an algorithm that identifies the top N toys out of a list of quotes and list of toys.
Computers and Technology
1 answer:
timofeeve [1]3 years ago
5 0

Answer:

#include <iostream>

#include <string>

#include <vector>

#include <regex>

#include <cstring>

using namespace std;

class Toy {

public:

   string name{};

   int count{0};

   // Constructor

   Toy(string n) {

       name = n;

   }

};

size_t findCaseInsensitive(string data, string toSearch, size_t pos = 0)

{

   // Convert complete given String to lower case

   transform(data.begin(), data.end(), data.begin(), ::tolower);

   // Convert complete given Sub String to lower case

   transform(toSearch.begin(), toSearch.end(), toSearch.begin(), ::tolower);

   // Find sub string in given string

   return data.find(toSearch, pos);

}

void swapToys(Toy* toy1, Toy* toy2 ) {

   Toy temp = *toy1;

   *toy1 = *toy2;

   *toy2 = temp;

}

vector<Toy*> sortToyVector(vector<Toy*> t) {

   for (int i = 0; i < t.size(); i++) {

       for (int j = 0; j < t.size()- i - 1; j++) {

           if (t[j]->count < t[j + 1]->count) {

               swapToys(t[j], t[j + 1]);

           }

           else if (t[j]->count == t[j + 1]->count) {

               const char* lstr = { t[j]->name.c_str() };

               const char* rstr = { t[j+1]->name.c_str() };

               if (strcmp(lstr, rstr) > 0) {

                   swapToys(t[j], t[j + 1]);

               }

           }

           else;

       }

   }

   return t;

}

void displayTopToys(

   int numToys,

   int topToys,

   vector<string> toys,

   int numQuotes,

   vector<string> quotes

)

{  

   vector<Toy*> tvec{};

   for (int i = 0; i < toys.size(); i++) {

       Toy* t = new Toy(toys[i]);

       for (int j = 0; j < quotes.size(); j++) {

           size_t pos{ 0 };

           pos = findCaseInsensitive(quotes[j], toys[i]);

           while (pos != std::string::npos) {

               t->count = t->count + 1;

               pos = findCaseInsensitive(quotes[j], toys[i], pos + toys[i].length());

           }

       }

       cout << t->name << " :" << t->count << endl;

       tvec.push_back(t);

   }

   tvec = sortToyVector(tvec);

   cout << endl;

   cout << endl;

   cout << "Top Toys:" << endl;

   for (int i = 0; i < tvec.size(); i++) {

       cout << i << ": " << tvec[i]->name << " :" << tvec[i]->count << endl;

   }

   cout << endl;

   cout << endl;

   cout << "Number of Top Toys: " << topToys << endl;

   cout << "Top Toys:" << endl;

   for (int i = 0; i < topToys; i++) {

       cout << i << ": " << tvec[i]->name << endl;

   }

   cout << endl;

   cout << endl;

}

int main() {

   // Inputs

   int numToys = 6;

   int topToys = 2;

   vector<string> toys = { "elmo", "elsa", "legos", "drone", "tablet", "warcraft" };

   int numQuotes = 6;

   vector<string> quotes = {

   "Emo is the hottest of the season! Elmo will be on every kid's wishlist!",

   "The new Elmo dolls are super high quality",

   "Expect the Elsa dolls to be very popular this year",

   "Elsa and Elmo are the toys I'll be buying for my kids",

   "For parents of older kids, look into buying them a drone",

   "Warcraft is slowly rising in popularity ahead of the holiday season"

   };

   displayTopToys(numToys, topToys, toys, numQuotes, quotes);

   return 0;

}  

Input:

The input to the function/method consists of five arguments:

  numToys, an integer representing the number of toys

   topToys, an integer representing the number of top toys your algorithm needs to return;

   toys, a list of strings representing the toys,

   numQuotes, an integer representing the number of quotes about toys;

   quotes, a list of strings that consists of space-sperated words representing articles about toys

Output:

Return a list of strings of the most popular N toys in order of most to least frequently mentioned

Note:

The comparison of strings is case-insensitive. If the value of topToys is more than the number of toys, return the names of only the toys mentioned in the quotes. If toys are mentioned an equal number of times in quotes, sort alphabetically.

Explanation:

C++ was use to code the above algorithm.

You might be interested in
Which is the least technically experienced technical support group?
Nezavi [6.7K]

Answer:

Tier 1 support

Explanation:

Of the given options, tier 1 support technical group is the least experienced group. This group of technicians is also referred to as level 1 technical group.

The tier 1 or level support are made up of junior technician, and they have few technical understandings.

Their roles include email response and basic troubleshooting, attending to phone calls, among others.

When a problem cannot be solved by tier 1 support  technicians, they pass the problem to tier 2 support technicians,  

5 0
3 years ago
True or false? Main Content (MC) may include links on the page.
nevsk [136]
True. 
You can create a permalink which is also a link inside your main content to link your topic to another similar or helpful topic. Sometimes we can put it in a way that we only pasted the entire link or just used a work then insert the link inside that work to redirect to another page

3 0
4 years ago
A stealth network attack in which an unauthorized person gains access to a network and remains undetected for a long time is ref
polet [3.4K]

Answer:

"Advanced persistent threat " is the right one.

Explanation:

  • APT seems to be a clandestine cyber assault on something like a network connection where another assailant achieves and retains unauthorized knowledge to the communication network, however impossible to conceive for a considerable period.
  • They represent compound channel assaults that use different components including various approaches of attack.
6 0
3 years ago
How are you doing this fine morning <br><br> hi
notka56 [123]
It's evening................∆
6 0
4 years ago
Read 2 more answers
To turn off the AutoCorrect features, navigate to the AutoCorrect menu and deselect the box labeled_____.
barxatty [35]
Option A-Show AutoCorrect buttons, then you have the options to hide the autocorrect or to turn it on/off
4 0
4 years ago
Read 2 more answers
Other questions:
  • If an ARQ algorithm is running over a 40-km point-to-point fiber optic link then:
    12·1 answer
  • Help me out for this one
    12·1 answer
  • You want to create Web pages that can easily adapt to and serve multimedia content to smartphones, tablets, gaming devices and s
    13·1 answer
  • Write a program to convert a fraction to a decimal. Have your program ask for the numerator first, then the denominator. Make su
    10·1 answer
  • Name two ways you can identify the pid number of the login shell.
    13·1 answer
  • "If a program attempts to modify (or, sometimes, even to read) the contents of memory locations that do not belong to it, the op
    11·1 answer
  • Why are new versions of applications packages released often ​
    9·1 answer
  • HELP ASAP !!! What should be a one-page document?
    7·1 answer
  • A source is:
    15·2 answers
  • Write 3 things that can't be done without technology.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!