虽然是水题,但是容易错。参照了紫书的代码可以写的很简洁。主要还是注意常量数组的使用,能让代码变得简单许多
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <stack>
#include <math.h>
#pragma warning ( disable : 4996 ) using namespace std; int Max( int a, int b ) { return a>b?a:b; }
int Min( int a, int b ) { return a>b?b:a; } const int inf = 0x3f3f3f3f;
const int maxn = + ;
const char T[] = "A...3..HIL.JM.O...2TUVWXY51SE.Z..8.";
char test[]; char getM( char c )
{
if (isalpha(c)) return T[c-'A'];
else return T[c-''+];
}
int main()
{
while ( ~scanf("%s", test) )
{
int len = strlen(test);
bool isP = true, isM = true;
for ( int i = ; i < (len+) / ; i++ )
{
if ( test[i] != test[len--i] ) isP = false;
if ( getM(test[i]) != test[len--i] ) isM = false;
}
if ((!isP)&&(!isM)) printf( "%s -- is %s\n\n", test, "not a palindrome." );
if (isP&&(!isM)) printf( "%s -- is %s\n\n", test, "a regular palindrome." );
if ((!isP)&&isM) printf( "%s -- is %s\n\n", test, "a mirrored string." );
if (isP&&isM) printf( "%s -- is %s\n\n", test, "a mirrored palindrome." );
}
return ;
}