zoukankan      html  css  js  c++  java
  • uva 401 Palindromes

    题目: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
  • 相关阅读:
    VMware Workstation-虚拟机的安装
    Linux操作系统-命令-free
    Linux操作系统-命令-vmstat
    抛出一个异常
    字符集
    页面缓存
    表单域
    弹出式说明
    canselBubble 和 stopPropagation理解
    JS---递归函数理解
  • 原文地址:https://www.cnblogs.com/overflow/p/3138936.html
Copyright © 2011-2022 走看看