Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <string>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int CountAndAddNewDogs(const vector<string>& new_dogs, const map<string, int>& max_amount,
- map<string, int>& shelter) {
- map<string, int> my_max_amount;
- for (auto& [k, v] : max_amount) {
- my_max_amount.insert({k, v});
- }
- int counter = 0;
- for (const string& dog : new_dogs) {
- int delta = my_max_amount[dog] - shelter[dog];
- if (delta > 0) {
- ++counter;
- ++shelter[dog];
- }
- }
- return counter;
- }
- int main() {
- map<string, int> shelter = {{"landseer"s, 1}, {"otterhound"s, 2}, {"pekingese"s, 2}, {"pointer"s, 3}};
- const map<string, int>& max_amount = {{"landseer"s, 2}, {"otterhound"s, 3}, {"pekingese"s, 4}, {"pointer"s, 7}};
- const vector<string>& new_dogs = {"landseer"s, "otterhound"s, "otterhound"s, "otterhound"s, "pointer"s};
- cout << CountAndAddNewDogs(new_dogs, max_amount, shelter) << endl;
- /*
- for (auto& [k, v] : shelter) {
- cout << k << " " << v << endl;
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment