Advertisement
giGii

counter2

Aug 16th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 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_1(const vector<string>& new_dogs, const map<string, int>& max_amount,
  10.                        map<string, int>& shelter) {
  11.     return count_if(max_amount.begin(), max_amount.end(), [&shelter, &new_dogs, &max_amount](const auto& [k, v]) {
  12.         return k == "pekingese"s; // рассчитывал, что должно вернуться true на моменте {"pekingese"s, 4}, и count_if засчитает 1, а функция вернет 1
  13.     });
  14. }
  15.  
  16. int CountAndAddNewDogs_2(const vector<string>& new_dogs, const map<string, int>& max_amount,
  17.                        map<string, int>& shelter) {
  18.     return count_if(max_amount.begin(), max_amount.end(), [&shelter, &new_dogs, &max_amount](const auto& dog) {
  19.         return max_amount[dog] >= 4; // рассчитывал, что должно вернуться true на моменте {"pekingese"s, 4} и {"pointer"s, 7}, и count_if засчитает 1 и 1, а функция вернет 2
  20.     });
  21. }
  22.  
  23. int CountAndAddNewDogs_3(const vector<string>& new_dogs, const map<string, int>& max_amount,
  24.                        map<string, int>& shelter) {
  25.     return count_if(max_amount.begin(), max_amount.end(), [&shelter, &new_dogs, &max_amount](const auto& dog) {
  26.         return dog == "pekingese"s; // рассчитывал, что должно вернуться true на моменте {"pekingese"s, 4}, и count_if засчитает 1, а функция вернет 1
  27.     });
  28. }
  29.  
  30. int main() {
  31.  
  32.     map<string, int> shelter = {{"landseer"s, 1}, {"otterhound"s, 2}, {"pekingese"s, 2}, {"pointer"s, 3}};
  33.     const map<string, int> max_amount = {{"landseer"s, 2}, {"otterhound"s, 3}, {"pekingese"s, 4}, {"pointer"s, 7}};
  34.     const vector<string> new_dogs = {"landseer"s, "otterhound"s, "otterhound"s, "otterhound"s, "pointer"s};
  35.  
  36.     cout << CountAndAddNewDogs_1,2,3(new_dogs, max_amount, shelter) << endl;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement