Advertisement
NyanCoder

Lab4\No4.cpp

Mar 20th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.     char str[256];
  5.     for (int i = 0; i < 256; i++) str[i] = 0;
  6.     std::cin.getline(str, 256);
  7.    
  8.     int cursor1 = 0, cursor2 = 0;
  9.    
  10.     // Двигаем правый курсор в конец строки
  11.     for (; str[cursor2] && str[cursor2] != '\n' && cursor2 < 256; cursor2++);
  12.     --cursor2; // Последний символ, который не конец строки
  13.    
  14.     bool condition = true;
  15.     for (; cursor1 < cursor2; cursor1++, cursor2--) {
  16.         // Пропускаем пробелы
  17.         for (; str[cursor1] == ' ' && cursor1 < cursor2; cursor1++);
  18.         for (; str[cursor2] == ' ' && cursor1 < cursor2; cursor2--);
  19.        
  20.         // Если симполы у курсоров не равны, то наша строка - не палиндром
  21.         if (str[cursor1] != str[cursor2]) {
  22.             condition = false;
  23.             break;
  24.         }
  25.     }
  26.    
  27.     if (condition)
  28.         std::cout << "YES";
  29.     else
  30.         std::cout << "NO";
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement