Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Определяет, будет ли слово палиндромом
- // text может быть строкой, содержащей строчные буквы английского алфавита и пробелы
- // Пустые строки и строки, состоящие только из пробелов, - это не палиндромы
- bool IsPalindrome(const string& text) {
- // Напишите недостающий код
- string reverse_text, text_without_spaces;
- for(char symbol : text){
- if(symbol != ' '){
- text_without_spaces += symbol;
- }
- }
- for(int i = text_without_spaces.size()-1; i>=0; --i)
- {
- reverse_text += text_without_spaces[i];
- }
- if(!reverse_text.empty() && reverse_text == text_without_spaces){
- return true;
- }else{
- return false;
- }
- }
- int main() {
- string text;
- getline(cin, text);
- if (IsPalindrome(text)) {
- cout << "palindrome"s << endl;
- } else {
- cout << "not a palindrome"s << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment