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 }
时间: 2024-12-27 23:45:55

uva 401.Palindromes的相关文章

UVa 401 Palindromes(字符串,回文)

 Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string i

UVa 401 Palindromes(简单字符串)

简单的判断是否是回文串.镜像串,然后自己写的真费劲,没逃掉刘汝佳的书,这里的代码很有技巧性,特别值得学习,额,其实他书上的代码都很精简 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

UVA 401 Palindromes(回文词)

 回文词 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 401 Appoint description:  acmparand  (2013-07-07)Luke  (2014-01-20) System Crawler  (2015-05-10) Description A regular palindrome is a string of

UVa 401 Palindromes(镜像回文字符串)

 题意  给一个字符串 判定其是否为回文串和镜像串  回文串很好判断  镜像串对于每一个字符用数组保存它的镜像字符就行了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才是镜像串 #include<cstdio> #include<cctype> #include<cstring> const int N = 35; int l; char s[N], mc[] = "A 3 HIL JM O 2TUVWXY5", mn[]

uvaoj 401 Palindromes

************************************************题目描述*************************************************** UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is

UVA 之401 - Palindromes

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from ri

回文词(Palindromes, UVa 401)

输入一个字符串,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后与原串相同,如abba和madam.所谓镜像串,就是左右镜像之后和原串相同,如2S和3AIAE.注意,并不是每个字符在镜像之后都能得到一个合法字符.(空白项表示该字符镜像后不能得到一个合法字符.) 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

Palindromes UVA - 401

题意参见紫书 #include<bits/stdc++.h> using namespace std; #define me(s) memset(s,0,sizeof(s)) #define _for(i,a,b) for(int i=(a);i<(b);++i) #define _rep(i,a,b) for(int i=(a);i<=(b);++i) #define mp make_pair #define pb push_back #define all(x) (x).beg

UVA 401

//Notes: 1.每个结果最后有2个\n\n 2.'A'->'A' 'B'->' ' 'E'->'3' 3.0与O要一样 #include <iostream> using namespace std; #include <cstdio> #include <string> #include <cstring> #include <cctype> string str0 = "_ABCDEFGHIJKLMNOPQR