#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *total = "A 3 HIL JM O 2TUVWXY5";
char *dig = "O1SE Z 8 ";
int
isParlin(char* s)
{
int len = strlen(s);
int i = 0;
char nepu[30] = {0};
for(;i<len;i++)
nepu[i] = s[len-1-i];
nepu[i] = '\0';
//printf("%s\n", nepu);
if(strcmp(s, nepu) == 0)
return 1;
return 0;
}
void
chgeZero(char *s)
{
int len = strlen(s);
int i = 0;
for(; i < len; i++)
if(s[i] == '0')
s[i] = 'O';
}
int
isMill(char *s)
{
int len = strlen(s);
int i = 0;
char nepu[30] = {0};
for(; i < len; i++)
if(s[len-1-i] >= 'A' && s[len-1-i] <= 'Z')
nepu[i] = total[s[len-1-i]-'A'];
else if(s[len-1-i] >= '0' && s[len-1-i] <= '9')
nepu[i] = dig[s[len-1-i]-'0'];
nepu[i] = '\0';
//printf("%s\n", nepu);
if(strcmp(nepu, s) == 0)
return 1;
return 0;
}
int
main(void)
{
char in[30] = {0};
char copy[30] = {0};
while(scanf("%s", in) != EOF)
{
strcpy(copy, in);
chgeZero(in);
int p = isParlin(in);
int q = isMill(in);
if( p ==0 && q == 0)
printf("%s -- is not a palindrome.\n\n", copy);
else if( p == 1 && q == 0)
printf("%s -- is a regular palindrome.\n\n", copy);
else if( p == 0 && q == 1)
printf("%s -- is a mirrored string.\n\n", copy);
else if( p == 1 && q == 1)
printf("%s -- is a mirrored palindrome.\n\n", copy);
memset(in, 0, sizeof in );
memset(copy, 0, sizeof copy);
}
return 0;
}
问题1: 在main方法中忘记写 return 0; Runtime Error
问题2: 没有弄清楚题目的意思,比如说 BBB 不是 镜像字符串