Advertisement
bogolyubskiyalexey

Untitled

Jan 26th, 2021
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1.  
  2. bool CheckPalindrome (string_view line) {
  3.     for (size_t i = 0; i < line.size() / 2; ++i) {
  4.         if (line[i] != line[line.size() - i - 1]) {
  5.             return false;
  6.         }
  7.     }
  8.     return true;
  9. }
  10.  
  11. size_t CountPalindromes(string_view line) {
  12.     size_t result = 0;
  13.     for (size_t i = 0; i < line.size(); ++i) {
  14.         if (line[i] != ' ') {
  15.             size_t j = i;
  16.             while (j < line.size() && line[j] != ' ') {
  17.                 ++j;
  18.             }
  19.             if (CheckPalindrome(line.substr(i, j - i))) {
  20.                 ++result;
  21.             }
  22.             i = j;
  23.         }
  24.     }
  25.     return result;
  26. }
  27.  
  28. std::string -> std::string_view ok
  29. std::string_view -> std::string& CE
  30.  
  31. void f(string_view& s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement