Geradot345

7.1

Dec 9th, 2020 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //Щеглов В.А. 19ВИ1
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. int counter(string S, string S1)
  9. {
  10. int count = 0;
  11. string::size_type position = 0;
  12. while ((position = S.find(S1, position)) != string::npos) {
  13. count++;
  14. position++;
  15. }
  16. return count;
  17. };
  18.  
  19. int word_count(string strings)
  20. {
  21. istringstream split(strings);
  22. vector<string> tokens;
  23. char split_char = ' ';
  24. for (string each; getline(split, each, split_char); tokens.push_back(each));
  25.  
  26. int count = 0;
  27.  
  28. for(auto& s: tokens) {
  29. if (counter(s, "А") == 3) {
  30. count += 1;
  31. };
  32. };
  33. return count;
  34. }
  35.  
  36. int main()
  37. {
  38. setlocale(LC_ALL, "Russian");
  39. cout << "Enter string s: ";
  40. string s;
  41. getline(cin, s);
  42. cout << "Completed string s: " << s << endl;
  43. cout << "Count of words with \"AAA\": " << word_count(s);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment