UVa 401 Palindromes(紫书习题--回文词)


       题目链接:UVa 401

       这是紫书上面的一道习题,题意就是求这个字符串是回文串还是镜像串,根据那个图打个表,第一次做没想到要这么做,很高端。


AC代码:

#include 
#include 
#include 
using namespace std;
const char* rev = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char* msg[] = {"not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome"};

char r(char ch){
  if(isalpha(ch))return rev[ch-'A'];
  return rev[ch - '0' + 25];
}

int main()
{
  char s[30];
  while(scanf("%s",s) != EOF){
    int len = strlen(s);
    int p = 1,m = 1;
    for(int i=0 ;i< (len+1)/2;i++){
      if(s[i] != s[len-1-i]) p = 0;
      if(r(s[i]) != s[len-1-i]) m = 0;
    }
    printf("%s -- is %s.\n\n",s,msg[m*2+p]);
  }
  return 0;
}



你可能感兴趣的:(补题补题补题)