uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342

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

Character Reverse Character Reverse Character Reverse
A A M M Y Y
B   N   Z 5
C   O O 1 1
D   P   2 S
E 3 Q   3 E
F   R   4  
G   S 2 5 Z
H H T T 6  
I I U U 7  
J L V V 8 8
K   W W 9  
L J X X    

注意是没有数字0的哦。(该题,数字 0 与字母 O 看成是一样的)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char mirror[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char *msg[] = {" -- 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-''+];
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s", s) != EOF) {
int len = strlen(s);
int p = , m = ; for (int i = ; i < len; i++) {
if (s[i] != s[len-i-]) p = ;
if (change(s[i]) != s[len-i-]) m = ;
}
printf("%s%s\n\n", s, msg[p+m*]);
}
return ;
}
上一篇:Ubuntu小点汇总,更新中...


下一篇:[leetcode] 题型整理之字符串处理