giGii

counter

Aug 16th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <map>
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int CountAndAddNewDogs(const vector<string>& new_dogs, const map<string, int>& max_amount,
  10.                        map<string, int>& shelter) {
  11.     map<string, int> my_max_amount;
  12.     for (auto& [k, v] : max_amount) {
  13.         my_max_amount.insert({k, v});
  14.     }
  15.     int counter = 0;
  16.     for (const string& dog : new_dogs) {
  17.         int delta = my_max_amount[dog] - shelter[dog];
  18.         if (delta > 0) {
  19.             ++counter;
  20.             ++shelter[dog];
  21.         }
  22.  
  23.     }
  24.  
  25.     return counter;
  26. }
  27.  
  28. int main() {
  29.     map<string, int> shelter = {{"landseer"s, 1}, {"otterhound"s, 2}, {"pekingese"s, 2}, {"pointer"s, 3}};
  30.     const map<string, int>& max_amount = {{"landseer"s, 2}, {"otterhound"s, 3}, {"pekingese"s, 4}, {"pointer"s, 7}};
  31.     const vector<string>& new_dogs = {"landseer"s, "otterhound"s, "otterhound"s, "otterhound"s, "pointer"s};
  32.    
  33.     cout << CountAndAddNewDogs(new_dogs, max_amount, shelter) << endl;
  34.     /*
  35.     for (auto& [k, v] : shelter) {
  36.         cout << k << " " << v << endl;
  37.     }
  38.      */
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment