-
感觉写得比较乱,真是情况中有情况!
-
#include <stdio.h>
-
#include <string.h>
-
#include <ctype.h>
-
-
char mirror[35]
-
= {'A','0','0','0','3','0','0','H','I','L','0','J','M','0','O','0','0','0','2','T','U','V','W','X','Y','5',
-
'1','S','E','0','Z','0','0','8','0'
-
};
-
-
int main()
-
{
-
void len1(char c);
-
char To_O(char c);
-
int is_mirror(char c1,char c2);
-
int i, j, len, pflag, mflag;
-
char str[10000], prins[10000];
-
while (scanf("%s", str)!=EOF)
-
{
-
strcpy(prins, str);//因为0和O被看作一样,所以附加保存原始数组最后输出
-
len = strlen(str);
-
mflag = 0;
-
pflag = 1;
-
if (len == 1)
-
{
-
len1(str[0]);
-
continue;
-
}
-
if (len%2==1)//字符串为奇数长度
-
{
-
i = len/2;
-
for (j=1; j<=i&&j<len-i; j++)
-
{
-
str[i-j] = To_O(str[i-j]);
-
str[i+j] = To_O(str[i+j]);
-
if (str[i-j]!=str[i+j])
-
{
-
pflag = 0;
-
if (is_mirror(str[i-j], str[i+j]))
-
{
-
mflag = 1;
-
}
-
else
-
{
-
mflag = 0;
-
break;
-
}
-
}
-
else
-
{
-
if (is_mirror(str[i-j], str[i+j]))
-
{
-
mflag = 1;
-
}
-
else
-
{
-
mflag = 0;
-
break;
-
}
-
}
-
}
-
}
-
else//偶数长度
-
{
-
i = len/2;
-
j = i-1;
-
for (; i<len; --j, ++i)
-
{
-
str[i] = To_O(str[i]);
-
str[j] = To_O(str[j]);
-
if (str[j]!=str[i])
-
{
-
pflag = 0;
-
if (is_mirror(str[j], str[i]))
-
{
-
mflag = 1;
-
}
-
}
-
else
-
{
-
if (is_mirror(str[j], str[i]))
-
{
-
mflag = 1;
-
}
-
else
-
{
-
mflag = 0;
-
break;
-
}
-
}
-
}
-
}
-
if (!mflag&&!pflag)
-
{
-
printf("%s -- is not a palindrome.nn", prins);
-
}
-
else
-
{
-
if (mflag&&pflag)
-
{
-
printf("%s -- is a mirrored palindrome.nn", prins);
-
}
-
else
-
{
-
if (pflag)
-
{
-
printf("%s -- is a regular palindrome.nn", prins);
-
}
-
else
-
{
-
printf("%s -- is a mirrored string.nn", prins);
-
}
-
}
-
}
-
}
-
return 0;
-
}
-
-
/*1个字符的特殊情况*/
-
void len1(char c)
-
{
-
if (isalpha(c))
-
{
-
if (mirror[c-'A']!='0')
-
{
-
printf("%c -- is a mirrored palindrome.nn", c);
-
}
-
else
-
{
-
printf("%c -- is a regular palindrome.nn", c);
-
}
-
}
-
else
-
{
-
if (c =='0')
-
{
-
c = 'O';
-
}
-
if (mirror[c-'A']!='0')
-
{
-
printf("%c -- is a mirrored palindrome.nn", c);
-
}
-
else
-
{
-
printf("%c -- is a regular palindrome.nn", c);
-
}
-
}
-
return;
-
}
-
-
/*判断是不是"反射"字母*/
-
int is_mirror(char c1, char c2)
-
{
-
if (isalpha(c1))
-
{
-
if (mirror[c1-'A'] == c2)
-
{
-
return 1;
-
}
-
else
-
{
-
return 0;
-
}
-
}
-
else
-
{
-
if (mirror[25+c1-'0'] == c2)
-
{
-
return 1;
-
}
-
else
-
{
-
return 0;
-
}
-
}
-
}
-
-
/*若为(数字)0, 变成(字母)O*/
-
char To_O(char c)
-
{
-
if (c == '0')
-
{
-
return 'O';
-
}
-
return c;
-
}
-
//程序完
2010-08-18 14:36 发表于百度空间,今搬至CU。
阅读(1051) | 评论(0) | 转发(0) |