Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
小弟跪求牛人(样例全部ok,附代码)#include <iostream> #include <string.h> #include <stdio.h> using namespace std; bool is_parlindrome(const char* src) { const char *end = src; while(*end) ++end; // has pointed to '' --end; while(src < end) { if(*src++ != *end--) return false; } return true; } bool is_mirrored(char* src) { char originalstr[10000]; strcpy(originalstr, src); int i; int len = strlen(src); for(i=0; i<len; i++) { switch(src[i]) { case 'A': src[i] = 'A'; break; case 'E': src[i] = '3'; break; case 'H': src[i] = 'H'; break; case 'I': src[i] = 'I'; break; case 'J': src[i] = 'L'; break; case 'L': src[i] = 'J'; break; case 'M': src[i] = 'M'; break; case 'O': src[i] = 'O'; break; case 'S': src[i] = '2'; break; case 'T': src[i] = 'T'; break; case 'U': src[i] = 'U'; break; case 'V': src[i] = 'V'; break; case 'W': src[i] = 'W'; break; case 'X': src[i] = 'X'; break; case 'Y': src[i] = 'Y'; break; case 'Z': src[i] = '5'; break; case '1': src[i] = '1'; break; case '2': src[i] = 'S'; break; case '3': src[i] = 'E'; break; case '5': src[i] = 'Z'; break; case '8': src[i] = '8'; break; default: return false; } } //now compare the two strings for(i=0; i<len; i++) { if(originalstr[i] != src[len - 1 - i]) return false; } return true; } int main() { char test[100]; while(scanf("%s", test) != EOF) { if((is_parlindrome(test) == false) && (is_mirrored(test) == false)) { cout<<test<<" -- is not a palindrome."<<endl; cout<<endl; continue; } if((is_parlindrome(test) == true) && (is_mirrored(test) == false)) { cout<<test<<" -- is a regular palindrome."<<endl; cout<<endl; continue; } if((is_parlindrome(test) == false) && (is_mirrored(test) == true)) { cout<<test<<" -- is a mirrored string."<<endl; cout<<endl; continue; } if((is_parlindrome(test) == true) && (is_mirrored(test) == true)) { cout<<test<<" -- is a mirrored palindrome."<<endl; cout<<endl; continue; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator