shushus

Спринт 3. Тестируем по плану.

Dec 8th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 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.     // Напишите недостающий код
  11.     string reverse_text, text_without_spaces;
  12.     for(char symbol : text){
  13.         if(symbol != ' '){
  14.             text_without_spaces += symbol;
  15.         }
  16.     }
  17.     for(int i = text_without_spaces.size()-1; i>=0; --i)
  18.         {
  19.             reverse_text += text_without_spaces[i];
  20.         }
  21.     if(!reverse_text.empty() && reverse_text == text_without_spaces){
  22.         return true;
  23.     }else{
  24.         return false;
  25.     }
  26. }
  27.  
  28. int main() {
  29.     string text;
  30.     getline(cin, text);
  31.  
  32.     if (IsPalindrome(text)) {
  33.         cout << "palindrome"s << endl;
  34.     } else {
  35.         cout << "not a palindrome"s << endl;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment