啊哈哈哈哈我记得去年最怕这种题了,这次细心的处理了一次,居然1A!
自从会了字符串反转后,感觉什么都变简单了。。。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
const int N = 20000;
const int INF = 1000000;
char s1[N] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"};
char s2[N] = {"A***3**HIL*JM*O***2TUVWXY51SE*Z**8*"};
int pal(char a[N])
{
char b[N];
strcpy(b, a);
strrev(b);
if(!strcmp(b, a)) return 1;
else return 0;
}
int mir(char a[N])
{
int len = strlen(a);
char b[N];
strcpy(b, a);
strrev(b);
int flag = 1;
for(int i = 0; i < len; i ++)
{
for(int j = 0; s1[j]; j ++)
{
if(a[i] == s1[j])
{
if(b[i] != s2[j])
{
flag = 0;
// printf("%c %c\n", a[i], b[i]);
break;
}
}
}
if(!flag) break;
}
if(flag) return 1;
else return 0;
}
int main()
{
// freopen("in.txt", "r", stdin);
char s[N];
while(~scanf("%s", s))
{
if(!pal(s) && !mir(s)) printf("%s -- is not a palindrome.\n", s);
else if(pal(s) && !mir(s)) printf("%s -- is a regular palindrome.\n", s);
else if(!pal(s) && mir(s)) printf("%s -- is a mirrored string.\n", s);
else printf("%s -- is a mirrored palindrome.\n", s);
printf("\n");
}
return 0;
}