UVa 401 - Palindromes
题目大意:判断一个串是不是镜像或者回文
解题思路:回文简单,中间往两边扫就行了,镜像从中间来,对应的字符要在两个串中比较
#include<stdio.h>
#include<string.h>
const char*cha="AEHIJLMOSTUVWXYZ12358";
const char *re="A3HILJMO2TUVWXY51SEZ8";
int isOK(char*str)
{
int i,len=strlen(str);
for(i=0; i<len/2; i++)
{
if(str[i] != str[len-i-1])
return 0;
}
return 1;
}
int isMirror(char*str){
int len = strlen(cha);
int lens =strlen(str);
int i,j;
if(lens==1)
{
for( i = 0;i <len;i++)
if( str[0]==cha[i])
break;
if(i==21 ||re[i]!=str[0])
return 0;
}
else if(lens > 1)
{
for( i = 0 ;i < lens/2 ;i++)
{
for( j = 0; j< len ; j++)
if(str[i]==cha[j])
break;
if(j==21||re[j]!=str[lens-i-1])
return 0;
}}
return 1;
}
char str[1000];
int main(){
memset(str,0,sizeof(str));
while(scanf("%s",str)!=EOF)
{
if(isOK(str))
{
if(isMirror(str))
printf("%s -- is a mirrored palindrome.\n\n",str);
else
printf("%s -- is a regular palindrome.\n\n",str);
}
else
{
if(isMirror(str))
printf("%s -- is a mirrored string.\n\n",str);
else
printf("%s -- is not a palindrome.\n\n",str);
}
}
return 0;
}