Aleksandr_Grigoryev

палиндром

Mar 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool palindrom(string str)
  6. {
  7.     for (int i = 0; i<str.length() / 2; i++)
  8.         if (str[i] != str[str.size() - 1 - i])
  9.             return false;
  10.     return true;
  11. }
  12.  
  13. int main()
  14. {
  15.     string s, word;
  16.     cout << "S = ";
  17.     getline(cin, s);
  18.     int k = 0;
  19.     int i = 0;
  20.     while (i<s.length())
  21.     {
  22.         if ((s[i]) >= 'a' && s[i] <= 'z')
  23.         {
  24.             word = "";
  25.             while (i<s.length() &&((s[i]) >= 'a' && s[i] <= 'z'))
  26.             {
  27.                 word.append(1,s[i]);
  28.                 ++i;
  29.             }
  30.             if (palindrom(word))
  31.                 k++;
  32.         }
  33.         else ++i;
  34.     }
  35.     cout << "kol-vo=" << k;
  36.     system("pause");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment