紫书 p48 例题 回文词

<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

const char* a="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char* b[]={" -- is not a palindrome."," -- is a regular palindrome."," -- is a mirrored string."," -- is a mirrored palindrome."};

char change(char s)
{
    if(isalpha(s))return a[s-'A'];
    return a[s-'0'+25];
}

int main()
{
    char str[21];
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str),p=1,q=1;
        for(int i=0;i<(len+1)/2;i++)
        {
            if(str[i]!=str[len-i-1])p=0;
            if(change(str[i])!=str[len-i-1])q=0;
        }
        printf("%s%s\n\n",str,b[p+q*2]);
    }
    return 0;
}
</span>

isalpha:判断字符是否为英文字符,若为小写返回2,大写返回1,不是字母返回0.

isdigit:判断字符是否为数字0~9,是,返回TRUE,否则,返回NULL(0)。

输出使用的数组注意

注意下判断是否为镜像串的方法。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值