uva 401.Palindromes
Posted windysai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 看成是一样的)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 1000 + 5; 8 char mirror[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; 9 const char *msg[4] = {" -- is not a palindrome.", " -- is a regular palindrome.", " -- is a mirrored string.", " -- is a mirrored palindrome."}; 10 char s[maxn]; 11 12 char change(char ch) 13 { 14 if (ch >= ‘A‘ && ch <= ‘Z‘) 15 return mirror[ch-‘A‘]; 16 return mirror[ch-‘0‘+25]; 17 } 18 19 int main() 20 { 21 #ifndef ONLINE_JUDGE 22 freopen("in.txt", "r", stdin); 23 #endif // ONLINE_JUDGE 24 25 while (scanf("%s", s) != EOF) { 26 int len = strlen(s); 27 int p = 1, m = 1; 28 29 for (int i = 0; i < len; i++) { 30 if (s[i] != s[len-i-1]) p = 0; 31 if (change(s[i]) != s[len-i-1]) m = 0; 32 } 33 printf("%s%s\n\n", s, msg[p+m*2]); 34 } 35 return 0; 36 }
以上是关于uva 401.Palindromes的主要内容,如果未能解决你的问题,请参考以下文章