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) {
- bool res = false;
- if (text.empty())
- return res;
- for (auto it1=text.begin(), it2=text.end()-1; it1 < it2;it1++,it2--) {
- while (*it1 == ' '&&it1<text.end()-1)
- it1++;
- while (*it2 == ' '&&it2>text.begin())
- it2--;
- if (it1 == text.end()-1 && it2 == text.begin()&&(*it1==' '&&*it2==' ')) {
- break;
- }
- if (tolower(*it1) == tolower(*it2)) {
- res = true;
- continue;
- }
- if (tolower(*it1) != tolower(*it2)) {
- res = false;
- break;
- }
- }
- return res;
- }
- 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