分别是UVa 401和10082
大概意思就是,利用常量数组,可以简化很多代码。以后多用。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
const char*rev="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char*msg[]={"not a palindrome","a regular palindrome",
"a mirrored string","a mirrored palindrome"};
char r(char ch)
{
if(isalpha(ch))
return rev[ch-'A'];
return rev[ch-'0'+25];
}
int main()
{
char s[30];
int i;
while(scanf("%s",s)==1)
{
int len=strlen(s);
int p=1,m=1;
for(i=0;i<(len+1)/2;i++)
{
if(s[i]!=s[len-1-i])
p=0;
if(r(s[i])!=s[len-1-i])
m=0;
}
printf("%s-- is %s.
",s,msg[m*2+p]);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
char s[]="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
int main()
{
int c,i;
while((c=getchar())!=EOF)
{
for(i=1;s[i]&&s[i]!=c;i++);
if(s[i])
putchar(s[i-1]);
else
putchar(c);
}
return 0;
}
代码来自书本。菜鸟见题不会。继续加油吧。哎·······