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

UVA 401

时间:2015-02-24 17:30:01      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:


//Notes:
  1、每个结果最后有2个\n\n
  2、‘A‘->‘A‘ ‘B‘->‘ ‘ ‘E‘->‘3‘
  3、0与O要一样
#include <iostream>
using namespace std;
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
string str0 = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
string str1 = "_A   3  HIL JM O   2TUVWXY51SE Z  8 0";
//»ØÎÄpalindrome
bool isPalindromeString(string str){
    for(int i = 0, len = str.length(); i <= len/2; i++)
        if(str[i] != str[len-i-1]) return 0;
    return 1;
}
bool isMirroedString(string str){
    for(int i = 0, len = str.length(); i <= len/2; i++){
        if((str[i] == ‘0‘ && str[len-1-i]==‘O‘) || (str[i] == ‘O‘ && str[len-i-1]==‘0‘)) continue;
        else if(str1[str0.find(str[i])] != str[len-i-1]) return 0;
    }
    return 1;
}
int main(){
    //freopen("data.in", "r", stdin);
    string string;
    while(cin >> string){
        if(isMirroedString(string)){
           if(isPalindromeString(string)) cout << string << " -- is a mirrored palindrome.";
           else  cout << string << " -- is a mirrored string.";
        }else{
            if(isPalindromeString(string)) cout << string << " -- is a regular palindrome.";
            else cout << string << " -- is not a palindrome.";
        }
        cout << "\n\n";
    }
    return 0;
}

  

UVA 401

标签:

原文地址:http://www.cnblogs.com/wbstackpop/p/4298791.html

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