Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the function below: Code in C++ When a Thumbtack user creates a new project, we recommend the best Pros for the job based on

image text in transcribed

image text in transcribed

Complete the function below:

image text in transcribed

Code in C++

When a Thumbtack user creates a new project, we recommend the best Pros for the job based on a metric called the Pro Matching Score (PMS). This score is calculated using two factors the distance the Pro would have to travel to the job, and the Pro's average rating. More specifically, PMS is defined as (max_distance - distance) + rating where max_distances the maximal distance that any Pro has from the given user. Naturally, a higher PMS means the Pro is a better match for the project You have an array that represents the Pros who are available to complete a new project for a user where each element of the array is a distance, rating] tuple distance is the distance of the Pro from the user's project location, and rating is their overal rating Given the array pros for a specific project determine the kPros who are best suited to complete it based on their Pro Matching Score. Return a list of the indices (0-based) at which these Pros appeared in the original pros array, sorted by their PMS score. In the case of a PMS tie the Pro with the smaller index goes first Example For pros - [(5, 4], [4, 3), (6, 5), (3, 5]] and k = 2, the output should be bestPros(pros, k) = [3, 1]. The PMSs of the Pros are: oth pro: (6 - 5) * 4 - 4 1st pro: (6 - 4) * 3 - 6 2nd pro: (6 - 6) * 5 - B; 3rd pro: (6 - 3) * 5 - 15. The output is [3, 1] since the Pros at indices 1 and 3 have the highest scores. Since pro[3] has a higher PMS than pro[1]. index 3 appears first in the array Input/Output [execution time limit] 4 seconds (is) [input] array array.integer pros An array of Pros. For each valid pros[1] contains two elements: pros(] ] is the distance of the 4th Pro from the user's location and pros (1) is the Pro's overall rating Guaranteed constraints: 1 s pros.lengths 184 1 spros[1]. Length - 2 1 spros[i][j] = 102 [input) integer k The number of Pros who should be recommended to complete the user's project. Guaranteed constraints: 1 sk s pros. Length (output) array.integer The indices of the k best Pros to complete the user's project from the original pros array, sorted by their Pro Matching Score. In the case of a PMS tie the Pro with the smaller index goes first. If there are fewer than k suitable Pros, return all of them 1 v #include 3 using namespace std; string Itrim(const string &); string rtrim(const string &); vector split(const string &); * Complete the 'bestPros' function below. * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. 2D_INTEGER_ARRAY pros * 2. INTEGER K 19 vector int> bestPros(vector> pros, int k) { 21 } 22 > int main()

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

Step: 3

blur-text-image

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

Managerial Accounting

Authors: Ray H. Garrison, Eric W. Noreen, Peter C. Brewer

12th Edition

978-0073526706, 9780073526706

Students also viewed these Databases questions