PersonalCorpus 版 (精华区)
904182 2002/06/15 07:42:38.671
Big Guava ... 401 C++ Accepted 0:00.020 64
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
int isRP(char *s)
{
int i,j;
j=strlen(s);
for (i=0;i<=j/2;i++) if (s[i]!=s[j-i-1]) break;
if (i>j/2) return 1; else return 0;
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input401.txt","r",stdin);
freopen("c:\\uva\\output401.txt","w",stdout);
#endif
char s[21],t[21];
int p,m,i,k;
while (gets(s)!=NULL) {
p=isRP(s);
strcpy(t,s);
for(i=0;i<strlen(s);i++)
switch(s[i]) {
case 'A': break;
case 'E': s[i]='3'; break;
case 'H': break;
case 'I': break;
case 'J': s[i]='L'; break;
case 'L': s[i]='J'; break;
case 'M': break;
case 'O': break;
case 'S': s[i]='2'; break;
case 'T': break;
case 'U': break;
case 'V': break;
case 'W': break;
case 'X': break;
case 'Y': break;
case 'Z': s[i]='5'; break;
case '1': break;
case '2': s[i]='S'; break;
case '3': s[i]='E'; break;
case '5': s[i]='Z'; break;
case '8': break;
default: i=strlen(s)+4;
}
if (i==strlen(s)+5) m=0; else {
for (i=0;i<strlen(s);i++) if (s[i]!=t[strlen(s)-i-1])
break;
if (i==strlen(s)) m=1; else m=0;
}
if ((p==0)&&(m==0)) {
printf("%s -- is not a palindrome.\n\n",t);
continue;
}
if ((p==1)&&(m==0)) {
printf("%s -- is a regular palindrome.\n\n",t);
continue;
}
if ((p==0)&&(m==1)) {
printf("%s -- is a mirrored string.\n\n",t);
continue;
}
if ((p==1)&&(m==1)) {
printf("%s -- is a mirrored palindrome.\n\n",t);
continue;
}
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.093毫秒