UVA - 401 Palindromes

解题思路:先用预处理处理保存下镜像的数据,再细心模拟,at the last but not least,In addition, after each output line(一个), you must print an empty line(又一个),即是两个换行。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=105;
char a[37];
char r[37];
void pre(){
    memset(a,0,sizeof(a));
    memset(r,0,sizeof(r));
    for(int i=0;i<26;i++){
        a[i]='A'+i;
        if(i==0)r[i]='A';
        if(i==4) r[i]='3';
        if(i==7||i==8||i==12||i==14||(i>=19&&i<=25))
            r[i]=a[i];
        if(i==9) r[i]='L';
        if(i==11)r[i]='J';
        if(i==18) r[i]='2';
        if(i==25) r[i]='5';
    }
    for(int i=1;i<=9;i++){
        a[25+i]='0'+i;
        if(i==1||i==8) r[25+i]=a[25+i];
        if(i==2) r[25+i]='S';
        if(i==3) r[25+i]='E';
        if(i==5) r[25+i]='Z';
    }
}
int is_same1(char ch1,char ch2){
    for(int i=0;i<35;i++){
        if(a[i]==ch1&&ch2==r[i]){
            return 1;
        }
    }
    return 0;
}
int is_mirror(char *ch){
    int len=strlen(ch);
    int mid=len/2;
    for(int l=0,h=len-1;l<=mid;l++,h--){
        if(!is_same1(ch[l],ch[h])){
        if(!(ch[l]=='0'&&(ch[h]=='0'||ch[h]=='O')||(ch[l]=='O'&&(ch[h]=='0'||ch[h]=='O'))))///o和0没差别
          return 0;
        }
    }
    return 1;
}
int is_pali(char*ch){
    int len=strlen(ch);
    int mid=len/2;
    for(int l=0,h=len-1;l<=mid;l++,h--){
        if(ch[l]!=ch[h]){
        if(!(ch[l]=='0'&&(ch[h]=='0'||ch[h]=='O')||(ch[l]=='O'&&(ch[h]=='0'||ch[h]=='O'))))
          return 0;
        }
    }
    return 1;
}
char res[N];
int main(){
    pre();
    while(scanf("%s",res)!=EOF){
        if(is_pali(res)){
            if(is_mirror(res)){
                printf("%s -- is a mirrored palindrome.\n\n",res);
            }
            else{
                 printf("%s -- is a regular palindrome.\n\n",res);
            }
        }
        else if(is_mirror(res)){
             printf("%s -- is a mirrored string.\n\n",res);
        }
        else{
            printf("%s -- is not a palindrome.\n\n",res);
        }
    }

return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值