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
Pls help.
melisa1 [442]

Answer:

First one would be work ethic.

Second one would be communication.

Third one would be adaptability.

Fourth one would be creativity.

(These are all guesses tho, so i'm not 100% sure !!)

Explanation:

6 0
3 years ago
Read 2 more answers
Sophia's plays her favorite game on her phone, where the game uses the phone's
nirvana33 [79]

Answer:

Augmented Reality

Explanation:

Augmented reality is a camera to overlay images on real-world scenery. Basically what the Pokemon GO app does.

8 0
1 year ago
8. Why is it important not to download pictures to your school or workplace network if you do not plan to use them?
Anni [7]

Answer:

not appropriate use of technology.

Explanation:

7 0
3 years ago
Your company has decided to hire a full-time video editor. You have been asked to find a system with the level of display qualit
mote1985 [20]

Answer:

"Resolution" and "Refresh rate" is the correct answer.

Explanation:

Resolution:

  • The resolution would be a step for describing the spatial brightness as well as cleanliness of something like a photograph but rather an image. It's always commonly being utilized for the performance evaluation of monitoring devices, digital photographs as well as numerous additional technology components.

Refresh rate:

  • A computer display as well as visualization technology feature that determines the equipment frequency as well as capacity for repainting or re-drawing that this whole presentation upon on-screen for every instant.
4 0
3 years ago
State one technique for overcoming external fragmentation in dynamic partitioning. Why is this technique of overcoming external
prisoha [69]

Compaction often gives solutions to the issues regarding external fragmentation.

One technique for overcoming external fragmentation in dynamic partitioning is

Compaction.

The reason why this technique of overcoming external fragmentation may be inefficient is because:

  • External fragmentation may need a lot of compaction and it is an expensive operation.

  • The use of contiguous allocation is often hard to fit processes into memory and also it is so difficult to grow or shrink the amount of memory allocated to a process.

  • Compaction only takes place when relocation is dynamic, and this also is expensive.

Compaction often shuffle memory notes or contents and then put or pile them up all in free memory and in one large block.

External fragmentation takes place when free memory is removed into small blocks.

Learn more from

brainly.com/question/23636593

4 0
2 years ago
Other questions:
  • Because all web browsers don't interpret html and css the same way, a major web development issue is
    13·1 answer
  • What is looping? the rerecording of sound first recorded on set the recording of sound on set the process of combining different
    11·1 answer
  • Most sim cards allow ___________ access attempts before locking you out.
    10·1 answer
  • The commands available from a menu change depending upon what you are doing.<br> True<br> False
    11·2 answers
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • A global project called One Laptop per Child is attempting to distribute low-cost laptop computers to children in developing cou
    10·1 answer
  • This is for career exploration, I need help please! &lt;3 HELPPPP
    8·2 answers
  • Select four tasks associated with operating system maintenance. Cleaning inside the computer Defragmenting the hard drive Deleti
    11·1 answer
  • Convert 128 GB into KB​
    8·2 answers
  • 8.10.8 guess the passcode codehs
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!