Advertisement
ahmad_zizo

401 - Palindromes

Jul 18th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. char charachter[21] = {'A','E','H','I','J','L','M','O','S','T','U','V','W','X','Y','Z','1','2','3','5','8'};
  7. char reverse_[21] = {'A','3','H','I','L','J','M','O','2','T','U','V','W','X','Y','5','1','S','E','Z','8'};
  8. int isPalindrome(char *str){
  9.     int i, len = strlen(str);
  10.     for(i = 0 ; i < len/2 ; i++)
  11.         if(str[i] != str[len - i - 1])
  12.             return 0;
  13.     return 1;
  14. }
  15.  
  16. int isMirrored(char *str){
  17.     int indx1, indx2 ,i, len = strlen(str);
  18.     for(i = 0 ; i < len/2; i++){
  19.         indx1 = indx2 = 0;
  20.         while(charachter[indx1] != str[i] && indx1 < 21)
  21.             indx1++;
  22.         while(reverse_[indx2] != str[len - i - 1] && indx2 < 21)
  23.             indx2++;
  24.         if(indx1 != indx2)
  25.             return 0;
  26.     }
  27.     return 1;
  28. }
  29.  
  30. int main()
  31. {
  32.     char str[21];
  33.     int x,y;
  34.     while(scanf("%s",str)!= EOF ){
  35.     x = isPalindrome(str);
  36.     y = isMirrored(str);
  37.     if(x == 0 && y == 0)
  38.         printf("%s -- is not a palindrome.\n\n",str);
  39.     else if(x==1 && y == 0)
  40.             printf("%s -- is a regular palindrome.\n\n",str);
  41.     else if(x == 0 && y == 1)
  42.             printf("%s -- is a mirrored string.\n\n",str);
  43.     else
  44.         printf("%s -- is a mirrored palindrome.\n\n",str);
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement