码迷,mamicode.com
首页 > 其他好文 > 详细

uva 401 Palindromes

时间:2015-07-16 00:28:47      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

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

 

uva 401 Palindromes

标签:

原文地址:http://www.cnblogs.com/yong-hua/p/4649767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!