Va 401 palindromes

Source: Internet
Author: User

# 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 ;}



The switch function in line 22 is really sad.

In fact, you can use two arrays!


CharOne [] ="Abcdefghijklmnopqrstuvwxyz123456789";CharTwo [] ="A 3 Hil JM o 2tuvwxy51se Z 8";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.