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

小白书训练-Palindromes

时间:2014-11-30 23:17:11      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   for   on   2014   

题目链接: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

标签:blog   http   io   ar   os   sp   for   on   2014   

原文地址:http://blog.csdn.net/codehypo/article/details/41630359

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