hdu1318 Palindromes(回文)

啊哈哈哈哈我记得去年最怕这种题了,这次细心的处理了一次,居然1A!偷笑

自从会了字符串反转后,感觉什么都变简单了。。。

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

const int N = 20000;
const int INF = 1000000;

char s1[N] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"};
char s2[N] = {"A***3**HIL*JM*O***2TUVWXY51SE*Z**8*"};

int pal(char a[N])
{
    char b[N];
    strcpy(b, a);
    strrev(b);
    if(!strcmp(b, a)) return 1;
    else return 0;
}

int mir(char a[N])
{
    int len = strlen(a);
    char b[N];
    strcpy(b, a);
    strrev(b);
    int flag = 1;
    for(int i = 0; i < len; i ++)
    {
        for(int j = 0; s1[j]; j ++)
        {
            if(a[i] == s1[j])
            {
                if(b[i] != s2[j])
                {
                    flag = 0;
   //                 printf("%c %c\n", a[i], b[i]);
                    break;
                }
            }
        }
        if(!flag) break;
    }
    if(flag) return 1;
    else return 0;
}

int main()
{
  //  freopen("in.txt", "r", stdin);
    char s[N];
    while(~scanf("%s", s))
    {
        if(!pal(s) && !mir(s)) printf("%s -- is not a palindrome.\n", s);
        else if(pal(s) && !mir(s)) printf("%s -- is a regular palindrome.\n", s);
        else if(!pal(s) && mir(s)) printf("%s -- is a mirrored string.\n", s);
        else printf("%s -- is a mirrored palindrome.\n", s);
        printf("\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值