uva 401 Palindromes

#include<iostream>、
#include<cctype>
using namespace std;
int main(){
    char a[36] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                   '1','2','3','4','5','6','7','8','9','#'};
    int b[36] =  {0, 35, 35, 35, 28, 35, 35, 7, 8, 11, 35, 9, 12, 35, 14, 35, 35, 35, 27, 19, 20, 21, 22, 23, 24, 30,
                  26, 18, 4, 35,25, 35, 35, 33, 35, 35};
    string s;
    while(cin >> s){
        int f1 = 1,f2 = 1;
        for(int i = 0,j = s.length() - 1; i <= j; i++,j--){
            if(s[i] != s[j])
                f1 = 0;
            if(isupper(s[i]))
                if(a[b[s[i] - 'A']]!= s[j])
                    f2 = 0;
            if(isdigit(s[i]))
                if(a[b[s[i]-'1' + 26]] != s[j])
                    f2 = 0;
        }
        if(f1 && f2)
            cout << s << " -- is a mirrored palindrome." << endl;
        else if(f1 && !f2)
            cout << s << " -- is a regular palindrome." << endl;
        else if(!f1 && f2)
            cout << s << " -- is a mirrored string." << endl;
        else
            cout << s << " -- is not a palindrome." << endl;
        cout << endl;
    }

    return 0;
}

 

posted @ 2015-07-15 22:52  杨永华  阅读(119)  评论(0编辑  收藏  举报