鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 手机系统开发 > J2ME > >

uva 401 Palindromes

来源:互联网 作者:佚名 时间:2015-09-25 05:44
题目:401-Palindromes 水题 #include cstdio #include iostream #include algorithm #include cmath #include cstring #include vector #include map using namespace std;map char , char m; void init(){ m.clear(); m[ ' 3 ' ]= ' E ' ; m[ ' E ' ]= ' 3

题目:401 - Palindromes

水题

 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
map<char,char>m;
void init()
{
    m.clear();
    m['3']='E';
    m['E']='3';
    m['L']='J';
    m['J']='L';
    m['S']='2';
    m['2']='S';
    m['Z']='5';
    m['5']='Z';
    m['H']='H';
    m['I']='I';
    m['0']='0';
    m['O']='O';
    m['Y']='Y';
    m['T']='T';
    m['U']='U';
    m['V']='V';
    m['W']='W';
    m['X']='X';
    m['1']='1';
    m['8']='8';
    m['A']='A';
}
bool is_palindrome(string s)
{
    int p=0,q=s.size()-1;
    while(p<q)
    {
        if(s[p]!=s[q])
        {
            return false;
        }
        p++;
        q--;
    }
    return true;
}
bool is_mirrored(string s)
{
    int p=0,q=s.size()-1;
    if(q==0)
    {
        if(m.find(s[q])!=m.end())
            return true;
        return false;
    }
    while(p<q)
    {
        if((s[p]=='O'||s[p]=='0')&&(s[q]=='0'||s[q]=='O'))
            ;
        else if(m.find(s[p])==m.end() || m[s[p]]!=s[q])
            return false;
        p++;
        q--;
    }
    return true;
}
int main()
{
    init();
    string s;
    while(cin>>s)
    {
        if(is_palindrome(s)&&is_mirrored(s))
            cout<<s<<" -- is a mirrored palindrome."<<endl;
        else if(!is_palindrome(s)&&is_mirrored(s))
            cout<<s<<" -- is a mirrored string."<<endl;
        else if(!is_mirrored(s)&&is_palindrome(s))
            cout<<s<<" -- is a regular palindrome."<<endl;
        else
            cout<<s<<" -- is not a palindrome."<<endl;
        cout<<endl;
    }
    return 0;
}
View Code

 

网友评论
<