标题:镜像字符串问题
取消只看楼主
预备大佬
Rank: 1
等 级:新手上路
帖 子:33
专家分:4
注 册:2018-11-8
结帖率:81.82%
已结贴  问题点数:20 回复次数:0 
镜像字符串问题
我的这个程序的镜像字符串判断错误,望大佬指点,测试数据2A3MEAS
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>
const char* rev = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char* msg[] = { "not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome" };
char r(char ch)
{
    if (isalpha(ch))
        return rev[ch - 'A'];
    return rev[ch - 'O' + 25];
}
int main()
{
    char s[30];
    while (scanf_s("%s", s,30) == 1)
    {
        int len = strlen(s);
        int p = 1, m = 1;
        for (int i = 0; i < (len + 1) / 2; i++)
        {
            if (s[i] != s[len - 1 - i])
                p = 0;//不是回文串
            if (r(s[i]) != s[len - 1 - i])
                m = 0;//不是镜像串
        }
        printf_s("%s -- is %s.\n\n", s, msg[m * 2 + p]);
    }
    system("pause");
    return 0;
}
搜索更多相关主题的帖子: 镜像 字符串 include char int 
2019-03-03 15:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493397-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017891 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved