标签:style blog color os io for 2014 html
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<map> #include<set> #include<vector> #include<queue> #include<stack> using namespace std; #define bug cout<<"bug----->\n" #define MAXN 10001; char same[]={"AHIMO0TUVWXY18"}; bool mirror(string s) { int len=s.length(); if(len%2) { int ok=1; int k=strlen(same); // cout<<len<<endl; // cout<<s[len/2]<<endl; for(int i=0;i<k;i++) if(s[len/2]==same[i]) { ok=0; break; } if(ok) return false; } for(int i=0;i<len/2;i++) { switch(s[i]) { case 'A': if(s[len-1-i]!='A') return 0;break; case 'E': if(s[len-1-i]!='3') return 0;break; case '3': if(s[len-1-i]!='E') return 0;break; case 'H': if(s[len-1-i]!='H') return 0;break; case 'I': if(s[len-1-i]!='I') return 0;break; case 'J': if(s[len-1-i]!='L') return 0;break; case 'L': if(s[len-1-i]!='J') return 0;break; case 'M': if(s[len-1-i]!='M') return 0;break; case 'O': if(s[len-1-i]!='0'&&s[len-1-i]!='O') return 0;break; case '0': if(s[len-1-i]!='0'&&s[len-1-i]!='O') return 0;break; case 'S': if(s[len-1-i]!='2') return 0;break; case '2': if(s[len-1-i]!='S') return 0;break; case 'T': if(s[len-1-i]!='T') return 0;break; case 'U': if(s[len-1-i]!='U') return 0;break; case 'V': if(s[len-1-i]!='V') return 0;break; case 'W': if(s[len-1-i]!='W') return 0;break; case 'X': if(s[len-1-i]!='X') return 0;break; case 'Y': if(s[len-1-i]!='Y') return 0;break; case 'Z': if(s[len-1-i]!='5') return 0;break; case '5': if(s[len-1-i]!='Z') return 0;break; case '1': if(s[len-1-i]!='1') return 0;break; case '8': if(s[len-1-i]!='8') return 0;break; default :return 0; } } return true; } bool pali(string s) { int len=s.length(); for(int i=0;i<len/2;i++) if(s[i]!=s[len-1-i]) return false; return true; } int main() { string s; while(cin>>s) { bool a1=mirror(s),a2=pali(s); if(a1&&a2) cout<<s<<" -- is a mirrored palindrome."<<endl; else if(a1) cout<<s<<" -- is a mirrored string."<<endl; else if(a2) cout<<s<<" -- is a regular palindrome."<<endl; else cout<<s<<" -- is not a palindrome."<<endl; cout<<"\n"; } return 0; }
22行的switch函数看的真是心酸。
其实可以用两个数组,就ok!
char one[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; char two[]="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
uva 401 Palindromes,布布扣,bubuko.com
标签:style blog color os io for 2014 html
原文地址:http://blog.csdn.net/code_or_code/article/details/38292983