Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int CountAndAddNewDogs(const vector<string>& new_dogs, const map<string, int>& max_amount, map<string, int>& shelter) {
- return count_if(new_dogs.begin(), new_dogs.end(), [&max_amount, &shelter](const string& name) {
- int& current_dog = shelter[name];
- if (current_dog < max_amount.at(name)) {
- ++current_dog;
- return true;
- }
- else
- return false;
- });
- }
- int main() {
- map<string, int> shelter{
- {"shepard"s, 1},
- {"corgie"s, 3},
- };
- map<string, int> max_amount{
- {"shepard"s, 2},
- {"corgie"s, 3},
- {"shiba inu"s, 1},
- };
- cout << CountAndAddNewDogs({ "shepard"s, "shiba inu"s, "shiba inu"s, "corgie"s }, max_amount, shelter) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement