您的位置:首页 > 其它

UVA 401-Palindromes

2015-08-20 10:47 471 查看
水题细节也很重要啊。。。

In addition, after each output line, you must print an empty line.

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
typedef long long ll;
using namespace std;
char const *ch = "AEHIJLMOSTUVWXYZ12358";
char const *re = "A3HILJMO2TUVWXY51SEZ8";
bool ispalindrome(string s)
{ int len=s.size();
for(int i=0;i<len/2;i++)
if(s[i]!=s[len-i-1]) return false;
return true;
}
bool ismirror(string s)
{ int len=s.size();
int table_len = strlen(ch);
int i,j;
if(len == 1)
{
for( j=0; j<table_len; j++)
{
if(ch[j] == s[0])
break;
}
if(j == 21 || re[j] != s[0])
return 0;
}
else
{ for(i=0; i<len/2; i++)
{
for(j=0; j<table_len; j++)
{
if(ch[j] == s[i])
break;
}
if(j == 21 || re[j] != s[len-i-1])
return 0;
}
return 1;

}

}
using namespace std;
int main()
{ string s;
while(cin>>s)
{
if(ispalindrome(s))
{if(ismirror(s)) {cout<<s<<" -- is a mirrored palindrome.\n"<<endl;continue;}
else {cout<<s<<" -- is a regular palindrome.\n"<<endl;continue;}}

else {
if(ismirror(s)) {cout<<s<<" -- is a mirrored string.\n"<<endl;continue;}
else {cout<<s<<" -- is not a palindrome.\n"<<endl;continue;}
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: