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 |
每行后有空格,没有镜像字母就不是镜像string(附AC代码)#include<iostream> #include<string> #include<stdio.h> using namespace std; bool isp(string king) { int j=king.length()-1; int i=0; while(j>=i) { if (king[j]!=king[i]) return false; else { i++; j--; } } return true; } bool ism(string king) { int j=king.length()-1; int i=0; string queen=king; for (int i=0;i<queen.length();i++) { char what=queen[i]; switch (what) { case 'E':queen[i]='3'; break; case 'J':queen[i]='L'; break; case 'L':queen[i]='J'; break; case 'S':queen[i]='2'; break; case 'Z':queen[i]='5'; break; case '2':queen[i]='S'; break; case '3':queen[i]='E'; break; case '5':queen[i]='Z'; break; case 'B': case 'C': case 'D': case 'F': case 'G': case 'K': case 'N': case 'P': case 'Q': case 'R': case '4': case '6': case '7': case '9':return false; }; }; i=0; for (int j=king.length()-1;j>=0;j--) { if (queen[j]!=king[i]) return false; else { i++; } } return true; } int main() { string king2; while(cin>>king2) { bool yzz=isp(king2); bool zzy=ism(king2); if (yzz && zzy) cout<<king2<<" -- is a mirrored palindrome."<<endl; if (!yzz && zzy) cout<<king2<<" -- is a mirrored string."<<endl; if(yzz && !zzy) cout<<king2<<" -- is a regular palindrome."<<endl; if (!yzz & !zzy) cout<<king2<<" -- is not a palindrome."<<endl; cout<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator