Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main() {
- char str[256];
- for (int i = 0; i < 256; i++) str[i] = 0;
- std::cin.getline(str, 256);
- int cursor1 = 0, cursor2 = 0;
- // Двигаем правый курсор в конец строки
- for (; str[cursor2] && str[cursor2] != '\n' && cursor2 < 256; cursor2++);
- --cursor2; // Последний символ, который не конец строки
- bool condition = true;
- for (; cursor1 < cursor2; cursor1++, cursor2--) {
- // Пропускаем пробелы
- for (; str[cursor1] == ' ' && cursor1 < cursor2; cursor1++);
- for (; str[cursor2] == ' ' && cursor1 < cursor2; cursor2--);
- // Если симполы у курсоров не равны, то наша строка - не палиндром
- if (str[cursor1] != str[cursor2]) {
- condition = false;
- break;
- }
- }
- if (condition)
- std::cout << "YES";
- else
- std::cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement