您的位置:首页 > 其它

uva 401.Palindromes

2016-04-02 22:22 357 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342

题目意思:给出一段字符串(大写字母+数字组成)。判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是。每个字母的镜像表格如下

CharacterReverseCharacterReverseCharacterReverse
AAMMYY
BNZ5
COO11
DP2S
E3Q3E
FR4
GS25Z
HHTT6
IIUU7
JLVV88
KWW9
LJXX
注意是没有数字0的哦。(该题,数字 0 与字母 O 看成是一样的)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

const int maxn = 1000 + 5;
char mirror[] = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char *msg[4] = {" -- is not a palindrome.", " -- is a regular palindrome.", " -- is a mirrored string.", " -- is a mirrored palindrome."};
char s[maxn];

char change(char ch)
{
if (ch >= 'A' && ch <= 'Z')
return mirror[ch-'A'];
return mirror[ch-'0'+25];
}

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE

while (scanf("%s", s) != EOF) {
int len = strlen(s);
int p = 1, m = 1;

for (int i = 0; i < len; i++) {
if (s[i] != s[len-i-1]) p = 0;
if (change(s[i]) != s[len-i-1]) m = 0;
}
printf("%s%s\n\n", s, msg[p+m*2]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: