Palindromes--uva401
problem link
https://vjudge.net/problem/UVA-401
analysis
这道题的技巧很好,很喜欢,感觉能学到蛮多东西
code
#include<cstdio>
#include<cstring>
#include<cctype>
const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[] = {"is not a palindrome.",
"is a regular palindrome.",
"is a mirrored string.",
"is a mirrored palindrome."};
char r(char c)
{
if(isalpha(c)) //是否为字母
{
return rev[c - 'A'];
}
return rev[c-'0'+25];
}
int main()
{
char s[30];
while(scanf("%s",s)==1)
{
int len = strlen(s);
int p=1, m=1;
for(int i=0; i*2<len+1; ++i)
{
if(s[i] != s[len-1-i])
p = 0; //不是回文串
if(s[i] != r(s[len-1-i]))
m = 0; //不是镜像串
}
printf("%s -- %s\n\n",s,msg[m*2+p]); //哈哈小技巧
}
return 0;
}