shushus

Спринт 1. Алгоритмы count и count_if. Задание 2.

Dec 3rd, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. bool StartsWithA(const string& str) {
  9.     if (!(str.empty())){
  10.         if(str[0] == 'a'||str[0]=='A'){
  11.         return true;
  12.     }else{
  13.         return false;
  14.     }
  15.     }else{
  16.         return false;
  17.     }
  18. }
  19.  
  20. int CountStartsWithA(const vector<string>& xs) {
  21.     // посчитайте число строк, начинающихс¤ на букву A или a
  22.     int cnt = count_if(xs.begin(), xs.end(), StartsWithA);
  23.     return cnt;
  24.    
  25. }
  26.  
  27. int main() {
  28.     // не меняйте тело main
  29.     cout << CountStartsWithA({"And"s, "another"s, "one"s, "gone"s, "another"s,
  30.                               "one"s
  31.                               "bites"s,
  32.                               "the"s, "dust"s});
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment