Question: Complete the function minimumBribes in the editor below. It must print an integer representing the minimum number of bribes necessary, or Too chaotic if the

Complete the function minimumBribes in the editor below. It must print an integer representing the minimum number of bribes necessary, or Too chaotic if the line configuration is not possible.

minimumBribes has the following parameter(s):

q: an array of integers

include

using namespace std;

vector split_string(string);

// Complete the minimumBribes function below. void minimumBribes(vector q) {

}

int main() { int t; cin >> t; cin.ignore(numeric_limits::max(), ' ');

for (int t_itr = 0; t_itr < t; t_itr++) { int n; cin >> n; cin.ignore(numeric_limits::max(), ' ');

string q_temp_temp; getline(cin, q_temp_temp);

vector q_temp = split_string(q_temp_temp);

vector q(n);

for (int i = 0; i < n; i++) { int q_item = stoi(q_temp[i]);

q[i] = q_item; }

minimumBribes(q); }

return 0; }

vector split_string(string input_string) { string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { return x == y and x == ' '; });

input_string.erase(new_end, input_string.end());

while (input_string[input_string.length() - 1] == ' ') { input_string.pop_back(); }

vector splits; char delimiter = ' ';

size_t i = 0; size_t pos = input_string.find(delimiter);

while (pos != string::npos) { splits.push_back(input_string.substr(i, pos - i));

i = pos + 1; pos = input_string.find(delimiter, i); }

splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));

return splits; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!