UVA401 - Palindromes

判断回文串 与  镜像对称的串

主要是要用常量简化代码  见代码


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define lson ((root<<1)+1)
#define rson ((root<<1)+2)
#define MID ((l+r)>>1)
typedef long long ll;
typedef pair<int,int> P;
#define For(i,t,n) for(int i=(t);i<(n);i++)
const int maxn=100005;
const int base=1000;
const int inf=999999;


char op(char c)
{
    char *s="AEHIJLMOSTUVWXYZ12358";//这里用常量形式  简化代码  不要用 if else 那样要写很多的代码
    char *s1="A3HILJMO2TUVWXY51SEZ8";
    int n=strlen(s);
    int i;
    for( i=0;i<n;i++)
        if(s[i]==c)break;
    if(i==n)return ' ';
    return s1[i];
}
bool is_hui(string a)
{
    int i;
    int n=a.size();
    for(i=0;i<n/2;i++)
    {
        if(a[i]!=a[n-1-i])
            return 0;
    }
    return 1;
}


bool is_mirr(string a)
{
    int i;
    int n=a.size();
     if(n==1&&op(a[0])!=a[0])return 0;
    string b;
    for(i=0;i<n/2;i++)
    {
        if(op(a[i])!=a[n-1-i])
            return 0;
    }


   return 1;
}
int main()
{
    int n,m,i,j,k,t;
    string a;
    while(cin>>a)
    {
        bool A=is_hui(a);
        bool B=is_mirr(a);
        if(A&&B)
           cout<<a<<" -- is a mirrored palindrome."<<endl<<endl;
        else if(A)
            cout<<a<<" -- is a regular palindrome."<<endl<<endl;
        else if(B)
            cout<<a<<" -- is a mirrored string."<<endl<<endl;
        else
            cout<<a<<" -- is not a palindrome."<<endl<<endl;


    }
    return 0;
}
















































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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值