UVa-Palindromes

时间:2023-12-18 23:12:44

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=342&mosmsg=Submission+received+with+ID+12044263

C++代码:

#include <cstdio>
#include <cstring>
int main()
{
char a[3000];
char s[3000];
char str[]={'A','*','*','*','3',
'*','*','H','I','L',
'*','J','M','*','O',
'*','*','*','2','T',
'U','V','W','X','Y',
'5','0','1','S','E','*',
'Z','*','*','8','*'};
while(scanf("%s",a)!=EOF)
{
strcpy(s,a);
int isp=0,ism=0;
int len=strlen(s);
int i,j;
for(i=0,j=len-1;i<=j;++i,--j)
{
if((s[i]=='0'||s[i]=='O')&&(s[j]=='0'||s[j]=='O'))
continue;
else
if(s[i]!=s[j])
break;
}
if(i>j)isp=1;
for(i=0;i<len;++i)
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=str[s[i]-'A'];
else
s[i]=str[s[i]-'0'+26];
}
for(i=0,j=len-1;i<len;++i,--j)
{
if((a[i]=='0'||a[i]=='O')&&(s[j]=='0'||s[j]=='O'))
continue;
else
if(a[i]!=s[j])
break;
}
if(i==len)
ism=1;
if(isp==0&&ism==0)
printf("%s -- is not a palindrome.\n\n",a);
else
if(isp==1&&ism==0)
printf("%s -- is a regular palindrome.\n\n",a);
else
if(isp==0&&ism==1)
printf("%s -- is a mirrored string.\n\n",a);
else
printf("%s -- is a mirrored palindrome.\n\n",a);
}
return 0; }

相关文章