Advertisement
chevengur

СПРИНТ № 3 | Введение в тестирование | Урок 3: Тестируем по плану

Nov 2nd, 2023
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. // Определяет, будет ли слово палиндромом
  7. // text может быть строкой, содержащей строчные буквы английского алфавита и пробелы
  8. // Пустые строки и строки, состоящие только из пробелов, - это не палиндромы
  9. bool IsPalindrome(const string& text) {
  10.     string sentences_without_space, reverse_sentences;
  11.    
  12.     for(const auto& ch: text){
  13.         if(ch == ' '){
  14.             sentences_without_space+= ch;
  15.         }
  16.     }
  17.  
  18.     for(int i = sentences_without_space.size(); i >= 0; --i){
  19.         reverse_sentences += sentences_without_space[i];
  20.     }
  21.  
  22.     if(!sentences_without_space.empty() && reverse_sentences == sentences_without_space){
  23.         return true;
  24.     }
  25.     else
  26.         return false;
  27.    
  28.     return false;
  29. }
  30.    
  31.  
  32.  
  33. int main() {
  34.     string text;
  35.     getline(cin, text);
  36.  
  37.     if (IsPalindrome(text)) {
  38.         cout << "palindrome"s << endl;
  39.     } else {
  40.         cout << "not a palindrome"s << endl;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement