AquaBlitz11

[t102] Check Palindrome (Medium)

Oct 9th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     char A[100010];
  8.     scanf("%[^\n]", A);
  9.     int n = strlen(A);
  10.     int i = 0, j = n-1;
  11.     int ok = 1;
  12.     while (i < j) {
  13.         if (!isalpha(A[i])) ++i;
  14.         else if (!isalpha(A[j])) --j;
  15.         else if (tolower(A[i]) != tolower(A[j])) {
  16.             ok = 0;
  17.             break;
  18.         }
  19.         else ++i, --j;
  20.     }
  21.     printf("%s\n", ok ? "YES" : "NO");
  22.     return 0;
  23. }
Add Comment
Please, Sign In to add comment