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 clear_text;
- for (char c : text) {
- if (c == ' ') {
- continue;
- }
- clear_text += c;
- }
- if (clear_text.size() == 0) {
- return false;
- }
- int length = clear_text.size();
- for (int i = 0; i < length / 2; ++i) {
- if (clear_text[i] != clear_text[length - i - 1]) {
- return false;
- }
- }
- return true;
- }
- 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