Question: Integer dataSize is read from input. Then, strings and integers are read and stored into string vector colorList and integer vector quantityList, respectively. Lastly, integer
Integer dataSize is read from input. Then, strings and integers are read and stored into string vector colorList and integer vector quantityList, respectively. Lastly, integer quantityThreshold is read from input.
Initialize lastPosition with -1.
Find the last element pair with a quantity not equal to quantityThreshold. If the element pair is found, assign lastPosition with the index of the element pair and output the color and quantity, separated by a space. End with a newline.
Ex: If the input is:
4 black 85 navy 86 teal 92 turquoise 91 85
Then the output is:
turquoise 91 last match found at # 3
-------------------------------------------------------------------------------------------------------------------------
#include
#include
using namespace std;
int main() {
int numElements;
int quantityThreshold;
int lastPosition;
int i;
cin >> numElements;
vector
vector
for (i = 0; i < colorList.size(); ++i) {
cin >> colorList.at(i);
cin >> quantityList.at(i);
}
cin >> quantityThreshold;
//YOUR CODE GOES HERE!//
if (lastPosition == -1) {
cout << "No result" << endl;
}
else {
cout << "last match found at # " << lastPosition << endl;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
