UVa 401 - Palindromes(回文词)

#include <iostream>
#include <cstdio>
#include <cstring>

char c[] = "AEHIJLMOSTUVWXYZ12358";
char r[] = "A3HILJMO2TUVWXY51SEZ8";
char out[4][50] =
{" -- is not a palindrome.",
" -- is a regular palindrome.",
" -- is a mirrored string.",
" -- is a mirrored palindrome."};
char buff[200];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif

    char *p;
    int n, i, pos;
    //1:not a palindrome 2:palindrome 3:mirrored string 4:mirrored palindrome
    int status;
    //equ:对应位置是否相等; inbuff:是否在buff中,且满足对应关系
    bool equ, inbuff;
    while(scanf("%s", buff) != EOF)
    {
        n = strlen(buff);
        equ = inbuff = true;

        for(i=0; i<=n/2; i++) {
            if(buff[i] != buff[n-1-i]) equ = false;
            if((p = strchr(c, buff[i])) == NULL) inbuff = false;
            else{
                pos = p - c;
                if(r[pos] != buff[n-1-i]) inbuff = false;
            }
        }
        if(equ) {
            if(inbuff) status = 4;
            else status = 2;
        } else {
            if(inbuff) status = 3;
            else status = 1;
        }
        printf("%s%s\n\n", buff, out[status-1]);
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值