Question
Integer numElements is read from input. Then, strings and integers are read and stored into string vector productList and integer vector numberList, respectively. Lastly, string
Integer numElements is read from input. Then, strings and integers are read and stored into string vector productList and integer vector numberList, respectively. Lastly, string productAsked and integer numberAsked are read from input.
Assign matchesFound with the number of element pairs that match both productAsked and numberAsked.
For each pair that matches productAsked and numberAsked, output "Exact match found at index " followed by the element pair's index. End with a newline.
Ex: If the input is:
4 sofa 99 dresser 161 sofa 99 sofa 100 sofa 99
Then the output is:
Exact match found at index 0 Exact match found at index 2 Total: 2
Code:
#include
#include
using namespace std;
int main() {
int numElements;
string productAsked;
int numberAsked;
int matchesFound;
unsigned int i;
cin >> numElements;
vector
vector
for (i = 0; i < productList.size(); ++i) {
cin >> productList.at(i);
cin >> numberList.at(i);
}
cin >> productAsked;
cin >> numberAsked;
/* Your code goes here */
cout << "Total: " << matchesFound << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started