UvaOj 401 - Palindromes

23 篇文章 0 订阅
11 篇文章 0 订阅

刷点水题先恢复下手感....

题目

代码:

#include<cstdio>
#include<cstring>

#define MAXM 1000
char fc[MAXM];
void init()
{
    memset(fc, 0, sizeof(fc));
    fc['A'] = 'A';
    fc['E'] = '3';
    fc['H'] = 'H';
    fc['I'] = 'I';
    fc['J'] = 'L';
    fc['L'] = 'J';
    fc['M'] = 'M';
    fc['O'] = 'O';
    fc['S'] = '2';
    fc['T'] = 'T';
    fc['U'] = 'U';
    fc['V'] = 'V';
    fc['W'] = 'W';
    fc['X'] = 'X';
    fc['Y'] = 'Y';
    fc['Z'] = '5';
    fc['1'] = '1';
    fc['2'] = 'S';
    fc['3'] = 'E';
    fc['5'] = 'Z';
    fc['8'] = '8';
}
#define MAXN 22
char s[MAXN];
int n;
int ispa(char s[])
{
    for(int i=0; i<n/2; i++)
    {
        if(s[i] != s[n-1-i]) return 0;
    }
    return 1;
}

int ismi(char s[])
{
    for(int i=0; i<n/2; i++)
    {
        if(!fc[s[n-1-i]] || s[i] != fc[s[n-1-i]]) return 0;
    }
    if(n%2)
    {
        if(!fc[s[n/2]] || s[n/2] != fc[s[n/2]]) return 0;
    }
    return 1;
}

int main()
{
    init();
    while(scanf("%s", s)!=EOF)
    {
        n = strlen(s);
        int isp = ispa(s);
        int ism = ismi(s);
        if(isp && ism)
        {
            printf("%s -- is a mirrored palindrome.\n", s);
        }
        else if(isp)
        {
            printf("%s -- is a regular palindrome.\n", s);
        }
        else if(ism)
        {
            printf("%s -- is a mirrored string.\n", s);
        }
        else
        {
            printf("%s -- is not a palindrome.\n", s);
        }
        printf("\n");
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值