判断回文串 与 镜像对称的串
主要是要用常量简化代码 见代码
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define lson ((root<<1)+1)
#define rson ((root<<1)+2)
#define MID ((l+r)>>1)
typedef long long ll;
typedef pair<int,int> P;
#define For(i,t,n) for(int i=(t);i<(n);i++)
const int maxn=100005;
const int base=1000;
const int inf=999999;
char op(char c)
{
char *s="AEHIJLMOSTUVWXYZ12358";//这里用常量形式 简化代码 不要用 if else 那样要写很多的代码
char *s1="A3HILJMO2TUVWXY51SEZ8";
int n=strlen(s);
int i;
for( i=0;i<n;i++)
if(s[i]==c)break;
if(i==n)return ' ';
return s1[i];
}
bool is_hui(string a)
{
int i;
int n=a.size();
for(i=0;i<n/2;i++)
{
if(a[i]!=a[n-1-i])
return 0;
}
return 1;
}
bool is_mirr(string a)
{
int i;
int n=a.size();
if(n==1&&op(a[0])!=a[0])return 0;
string b;
for(i=0;i<n/2;i++)
{
if(op(a[i])!=a[n-1-i])
return 0;
}
return 1;
}
int main()
{
int n,m,i,j,k,t;
string a;
while(cin>>a)
{
bool A=is_hui(a);
bool B=is_mirr(a);
if(A&&B)
cout<<a<<" -- is a mirrored palindrome."<<endl<<endl;
else if(A)
cout<<a<<" -- is a regular palindrome."<<endl<<endl;
else if(B)
cout<<a<<" -- is a mirrored string."<<endl<<endl;
else
cout<<a<<" -- is not a palindrome."<<endl<<endl;
}
return 0;
}