On a trip together, each payment is written down as who paid and how much: names[i] paid amounts[i]. Write spent_by(names, amounts) to return a map of how much each person paid in all. Both vectors are the same length.
spent_by({"Amy", "Bao", "Amy"}, {30, 12, 8})→{'Amy': 38, 'Bao': 12}spent_by({}, {})→{}map<string, int> spent_by(const vector<string> &names, const vector<int> &amounts)#include <map>
#include <string>
#include <vector>
using namespace std;
map<string, int> spent_by(const vector<string> &names, const vector<int> &amounts) {
map<string, int> total;
for (int i = 0; i < names.size(); i++) {
// your code here: add amounts[i] to names[i]'s total
}
return total;
}
Run tries the examples. When they look right, Submit.