首页 > 代码库 > 小白书训练-Palindromes

小白书训练-Palindromes

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342

题意镜像和回文串判断

代码:

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char s[30];

    while(cin >> s)
    {
        //pan duan hui wen
        int len = strlen(s);
        int hw = 1;
        for(int i = 0; i <= len / 2; i++)
        {
            if(s[i] != s[len - i - 1])
            {
                hw = 0;
                break;
            }
        }

        //pan duan jing xiang
        int jx = 1;
        for(int i = 0; i <= len / 2; i++)
        {
            if(s[i] == 'A')
            {
                if(s[len - i - 1] != 'A')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'E')
            {
                if(s[len - i - 1] != '3')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'H')
            {
                if(s[len - i - 1] != 'H')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'I')
            {
                if(s[len - i - 1] != 'I')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'J')
            {
                if(s[len - i - 1] != 'L')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'L')
            {
                if(s[len - i - 1] != 'J')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'M')
            {
                if(s[len - i - 1] != 'M')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'O')
            {
                if(s[len - i - 1] != 'O')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'O')
            {
                if(s[len - i - 1] != '0')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'S')
            {
                if(s[len - i - 1] != '2')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'T')
            {
                if(s[len - i - 1] != 'T')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'U')
            {
                if(s[len - i - 1] != 'U')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'V')
            {
                if(s[len - i - 1] != 'V')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'W')
            {
                if(s[len - i - 1] != 'W')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'X')
            {
                if(s[len - i - 1] != 'X')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'Y')
            {
                if(s[len - i - 1] != 'Y')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == 'Z')
            {
                if(s[len - i - 1] != '5')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '1')
            {
                if(s[len - i - 1] != '1')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '2')
            {
                if(s[len - i - 1] != 'S')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '3')
            {
                if(s[len - i - 1] != 'E')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '5')
            {
                if(s[len - i - 1] != 'Z')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '8')
            {
                if(s[len - i - 1] != '8')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '0')
            {
                if(s[len - i - 1] != '0')
                {
                    jx = 0;
                    break;
                }
            }
            else if(s[i] == '0')
            {
                if(s[len - i - 1] != 'O')
                {
                    jx = 0;
                    break;
                }
            }
            else
            {
                jx = 0;
                break;
            }
        }

        if(hw)
        {
            if(jx)
                cout << s << " -- is a mirrored palindrome." <<endl;
            else
                cout << s << " -- is a regular palindrome." <<endl;
        }
        else
        {
            if(jx)
                cout << s << " -- is a mirrored string." <<endl;
            else
                cout << s << " -- is not a palindrome." <<endl;
        }
        cout << endl;
    }
    return 0;
}

梦续代码:http://www.hypo.xyz

小白书训练-Palindromes