hdu1318
很繁琐,花了将近两个小时。。。。。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include"iostream"
using namespace std;
int main()
{
char a[100];
int i,j,L;
while(scanf("%s",a)!=EOF)
{
L=strlen(a);
int num=0,zf=0,sign=0;
for(i=0;i<L;i++)
{
if(a[i]>='0'&&a[i]<='9') { num=1;}
if(a[i]>='A'&&a[i]<='Z') { zf=1; }
if(a[i]=='O'||a[i]=='0') { sign=1;}
}
int count=0,mark=0;
if(L==1) //单独处理只有一个的情况
{
if(a[0]=='8'||a[0]=='0'||a[0]=='1') { mark++;}
if(a[0]>='T'&&a[0]<='Y')
{
mark++;
}
if(a[0] == 'H' || a[0] == 'I'||a[0]=='M'|| a[0]=='A'||a[0]=='O')
{
mark++;
}
if(a[0]=='2'||a[0]=='S'||a[0]=='5'||a[0]=='Z'||a[0]=='3'||a[0]=='E') count++;
printf("%s -- ",a);
if(mark==1) printf("is a mirrored palindrome.\n");
else if(mark==0&&count==1) printf("is a mirrored string.\n");
else printf("is a regular palindrome.\n");
}
else
{
if(num==1&&zf==1)
{
for( i=0, j=L-1; j>=L/2+1 , i<L/2; j--, i++)
{
if(a[i]>='A'&&a[i]<='Z')//处理字母的情况
{
if(a[i]>='T'&&a[i]<='Y')
{
if(a[i]==a[j]) { count++; mark++;}
}
else if(a[i] == 'H' || a[i] == 'I'||a[i]=='M'|| a[i]=='A')
{
if(a[i] == a[j]) { count++; mark++; }
}
else if( (a[i] == 'J'&&(a[j] == 'L'||a[j]=='J'))||(a[i]=='L'&&(a[j]=='J'||a[j]=='L')) ) count++;
else if( (a[i]=='E'&&(a[j]=='3'||a[j]=='E')) || (a[i]=='O'&&(a[j]=='0'||a[j]=='O'))||(a[i]=='Z'&&(a[j]=='5'||a[j]=='Z'))||(a[i]=='S'&&(a[j]=='2'||a[j]=='S' ))) count++;
}
else if(a[i]>='0'&&a[i]<='9') //处理数字的情况
{
if((a[i]=='8'&&a[j]=='8')||(a[i]=='0'&&a[j]=='0')||(a[i]=='1'&&a[j]=='1')){ mark++;}
if((a[i]=='2'&&(a[j]=='S'||a[j]=='2'))||(a[i]=='5'&&(a[j]=='Z'||a[j]=='5'))||(a[i]=='3'&&(a[j]=='E'||a[j]=='3'))||(a[i]=='0'&&(a[j]=='0'||a[j]=='O'))) count++;
else
{
if(a[i]==a[j]) count++;
}
}
}
}
else
{
for( i=0, j=L-1; j>=L/2+1 , i<L/2; j--, i++)
{
if(a[i]==a[j]) count++;
if((a[i]=='8'&&a[j]=='8')||(a[i]=='0'&&a[j]=='0')||(a[i]=='1'&&a[j]=='1')){ mark++;}
if(a[i]>='T'&&a[i]<='Y')
{
if(a[i]==a[j]) { mark++;}
}
if(a[i] == 'H' || a[i] == 'I'||a[i]=='M'|| a[i]=='A'||a[i]=='O')
{
if(a[i] == a[j]) { mark++; }
}
}
}
printf("%s -- ",a);
if(count==L/2)
{
if(mark==L/2) printf("is a mirrored palindrome.\n");
else if(num==1&&zf==1) printf("is a mirrored string.\n");
else if(num==0||zf==0) printf("is a regular palindrome.\n");
}
else printf("is not a palindrome.\n");
}
printf("\n");
}
return 0;
}