AquaBlitz11

[t103] Check Palindrome (Hard)

Oct 9th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 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, c = 0;
  11.     while (i < j) {
  12.         if (!isalpha(A[i])) ++i;
  13.         else if (!isalpha(A[j])) --j;
  14.         else if (tolower(A[i]) != tolower(A[j])) {
  15.             c = 0;
  16.             break;
  17.         }
  18.         else ++i, --j, ++c;
  19.     }
  20.     if (c == 0) {
  21.         printf("-\n");
  22.         return 0;
  23.     }
  24.     for (int i = 0; c > 0; ++i) {
  25.         if (isalpha(A[i])) {
  26.             printf("%c", tolower(A[i]));
  27.             --c;
  28.         }
  29.     }
  30.     printf("\n");
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment