Advertisement
Morass

Palindromes

Jan 16th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. char cmp[1024];
  4. int N;
  5. char getReverse(char c){
  6.     switch(c){
  7.         case 'A': return 'A';
  8.         case 'E': return '3';
  9.         case 'H': return 'H';
  10.         case 'I': return 'I';
  11.         case 'J': return 'L';
  12.         case 'L': return 'J';
  13.         case 'M': return 'M';
  14.         case 'O': return 'O';
  15.         case 'S': return '2';
  16.         case 'T': return 'T';
  17.         case 'U': return 'U';
  18.         case 'V': return 'V';
  19.         case 'W': return 'W';
  20.         case 'X': return 'X';
  21.         case 'Y': return 'Y';
  22.         case '5': return 'Z';
  23.         case 'Z': return '5';
  24.         case '1': return '1';
  25.         case '2': return 'S';
  26.         case '3': return 'E';
  27.         case '8': return '8';
  28.         default: return '\n';
  29.     }
  30. }
  31. bool isPalindrome(void){
  32.     for(int i(0),j(N-1);i<j;++i,--j)
  33.         if(cmp[i]!=cmp[j])
  34.             return false;
  35.     return true;
  36. }
  37. bool isReverse(void){
  38.     for(int i(0),j(N-1);i<=j;++i,--j)
  39.         if(cmp[i]!=getReverse(cmp[j]))
  40.             return false;
  41.     return true;
  42. }
  43. int main(void){
  44.     while(scanf("%s",cmp)==1){
  45.         printf("%s",cmp);
  46.         N=strlen(cmp);
  47.         if(isPalindrome())
  48.             if(isReverse())
  49.                 printf(" -- is a mirrored palindrome.\n\n");
  50.             else
  51.                 printf(" -- is a regular palindrome.\n\n");
  52.         else
  53.             if(isReverse())
  54.                 printf(" -- is a mirrored string.\n\n");
  55.             else
  56.                 printf(" -- is not a palindrome.\n\n");
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement