Advertisement
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 t;
- if (text.empty()) {
- return false;
- }
- for (int i = 0; i < text.size(); ++i) {
- if (text[i] != ' ') {
- t += text[i];
- }
- }
- if (t.empty()) {
- return false;
- }
- bool r = true;
- for (int i = 0; i < t.size() / 2; ++i) {
- if (t[i] == t[t.size() - 1 - i]){
- r = true;
- } else {
- r = false;
- break;
- }
- }
- return r;
- }
- 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
Advertisement