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
Let’s say you are given a number, a, and you want to find its square root. One way to do that is to start with a very rough gues
o-na [289]

Answer:

Check the explanation

Explanation:

package com.squarerrot;

public class SquareRoot {

/**

*

*/

public static double squareRoot(double input) {

System.out.println("Trace for input:" + input);

//random value initialized to 6 here

double output, guessValue = 6, previousValue = 0;

while (input - (output = approximateValue(input, guessValue)) >= 0.00005

&& previousValue != output) {

guessValue = output;

previousValue = output;

System.out.println(output);

}

return output;

}// end of method squareRoot

// calculate the approximate value

public static double approximateValue(double input, double start) {

return (start + (input / start)) / 2;

}// end of method approximateValue

// test the square root method

public static void main(String[] args) {

System.out.println("Square Root of 9:" + squareRoot(9));

System.out.println("Square Root of 16:" + squareRoot(16));

}// end of method main

}// end of the class

7 0
3 years ago
Complete the below method, isPalindrome(), that takes in a String and returns a boolean. The boolean should be true if the Strin
Salsk061 [2.6K]

Answer:

public static boolean isPalindrome(String word) {

   //TODO: Complete this method

   String reverse = "";  

       for (int i = (word.length()-1); i>=0; i--) {

           if(word.charAt(i)!=' '){

               reverse+=word.charAt(i);

           }

       }

   String without_space = word.replaceAll(" ", "");

   

   return reverse.equals(without_space);

   }

5 0
3 years ago
The web server administrator at your e-commerce company is concerned about someone using netcat to connect to the company web se
dangina [55]

Answer:

Banner Grabbing

Explanation:

Banner grabbing is a reconnaissance technique to retrieve information about a computer or about a network and its services. This is used by administrators to take inventory of systems and services on their network.

Banner grabbing is used to gain information about a remote server and is intruders sometimes use this technique to retrieve information about remote servers.  divulge software version numbers and other system information on network hosts. This is a technique of getting software banner information. This information may include operating system information, version and certain services and this helps hackers to attack the network. Banner grabbing can disclose vulnerable applications which can result in service misuse and exploitation.

Banner grabbing is done manually or automatically by using tools. Tools commonly used to perform banner grabbing are Telnet, Wget, nmap, zmap and Netcat etc.

4 0
4 years ago
When investigators find evidentiary items that aren't specified in a warrant or under probable cause what type of doctrine appli
Jet001 [13]
Search it up and it’ll tell you what doctrines it applies too
8 0
3 years ago
Refer to the color wheel to identify the color scheme.
morpeh [17]
C) monochromatic
Hope this helps!

btw make me brainliest?
4 0
4 years ago
Other questions:
  • What is a possible style of formatting your company could prefer?
    14·2 answers
  • Charges of the opposite tend to repel each other.
    9·2 answers
  • Invention I chose was radio.
    9·1 answer
  • The control programs managing computer hardware and software perform the _________ function to control and prioritize tasks perf
    8·1 answer
  • What are the basic steps in creating a new program
    5·1 answer
  • Anyone wanna play Bloons tower defense 5 im rank 52
    5·2 answers
  • Please help thank you !!!
    7·2 answers
  • You develop an app, and you don’t want anyone to resell it or modify it. This is an example of: A
    5·1 answer
  • What are the methods used in research methodology?
    12·1 answer
  • Examples of ________, which is hosted on a web site, include e-mail, word processing, tax preparation, and game programs.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!