您的位置:首页 > 其它

hdu1318 Palindromes(回文)

2016-03-09 22:03 477 查看
啊哈哈哈哈我记得去年最怕这种题了,这次细心的处理了一次,居然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
= {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"};
char s2
= {"A***3**HIL*JM*O***2TUVWXY51SE*Z**8*"};

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

int mir(char a
)
{
int len = strlen(a);
char b
;
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
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu