您的位置:首页 > 其它

Uva 401 - Palindromes

2013-11-26 21:23 369 查看
题目地址http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=342&mosmsg=Submission+received+with+ID+

虽然把代码写完了,也做了很多测试,还是wa,很心痛,有人能帮我看看代码错哪里吗

#include<iostream>
#include<string>
using namespace std;
char ref[100];
void Init(){
ref['A']='A';
ref['E']='3';
ref['H']='H';
ref['I']='I';
ref['J']='L';
ref['L']='J';
ref['M']='M';
ref['O']='O';
ref['S']='2';
ref['T']='T';
ref['U']='U';
ref['V']='V';
ref['W']='W';
ref['X']='X';
ref['Y']='Y';
ref['Z']='5';
ref['0']='O';
ref['1']='1';
ref['2']='S';
ref['3']='E';
ref['5']='Z';
ref['8']='8';
}
int IsPalindrome(string s){
int len=s.size();
int i=0,temp;
while((temp=(s[i]==s[len-1-i]))&&i<len/2){
i++;
}
return temp;
}
int IsMirrore(string s){
int len=s.size();
int i=0,temp;
while(i<=len/2){
if(s[i]!=ref[s[len-1-i]])
return 0;
i++;
}
return 2;
}
int main(){
string annotation[4]={" -- is not a palindrome",   //if the string is not a palindrome and is not a mirrored string
" -- is a regular palindrome.",                //if the string is a palindrome and is not a mirrored string
" -- is a mirrored string.",                   //if the string is not a palindrome and is a mirrored string
" -- is a mirrored palindrome."};              //if the string is a palindrome and is a mirrored string
string s;
Init();
while(cin>>s){
cout<<s<<annotation[IsMirrore(s)+IsPalindrome(s)]<<endl<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: