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 right to left.

A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. For example, the string "3AIAE" is a mirrored string because "A" and "I" are their own reverses, and "3" and "E" are each others' reverses.

A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string "ATOYOTA" is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. Of course, "A", "T", "O", and "Y" are all their own reverses.

A list of all valid characters and their reverses is as follows.

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    

Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.

Input

Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.

Output

For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.

STRING CRITERIA
" -- is not a palindrome." if the string is not a palindrome and is not a mirrored string
" -- is a regular palindrome." if the string is a palindrome and is not a mirrored string
" -- is a mirrored string." if the string is not a palindrome and is a mirrored string
" -- is a mirrored palindrome." if the string is a palindrome and is a mirrored string

Note that the output line is to include the -'s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.

In addition, after each output line, you must print an empty line.

Sample Input

NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA

Sample Output

NOTAPALINDROME -- is not a palindrome.

ISAPALINILAPASI -- is a regular palindrome.

2A3MEAS -- is a mirrored string.

ATOYOTA -- is a mirrored palindrome.
思路:此题考察回文串,镜像串,回文串就是正反字符串都相等,而镜像串则是要转换对应字符后反过来和以前的相同
#include<stdio.h>
#include<string.h>
#include<ctype.h>
const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"}; char r(char ch) {
if(isalpha(ch)) return rev[ch - 'A'];
return rev[ch - '0' + 25];
} int main() {
char s[30];
while(scanf("%s", s) == 1) {
int len = strlen(s);
int p = 1, m = 1;
for(int i = 0; i < (len+1)/2; i++) {
if(s[i] != s[len-1-i]) p = 0; // 不是回文串
if(r(s[i]) != s[len-1-i]) m = 0; // 不是镜像串
}
printf("%s -- is %s.\n\n", s, msg[m*2+p]);
}
return 0;
}

UVA401-Palindromes(紫书例题3.3)的更多相关文章

  1. 紫书 例题 11-13 UVa 10735(混合图的欧拉回路)(最大流)

    这道题写了两个多小时-- 首先讲一下怎么建模 我们的目的是让所有点的出度等于入度 那么我们可以把点分为两部分, 一部分出度大于入度, 一部分入度大于出度 那么显然, 按照书里的思路,将边方向后,就相当 ...

  2. 紫书 例题8-3 UVa 1152(中途相遇法)

    这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...

  3. 紫书 例题8-12 UVa 12627 (找规律 + 递归)

    紫书上有很明显的笔误, 公式写错了.g(k, i)的那个公式应该加上c(k-1)而不是c(k).如果加上c(k-1)那就是这一次 所有的红气球的数目, 肯定大于最下面i行的红气球数 我用的是f的公式, ...

  4. 紫书 例题8-4 UVa 11134(问题分解 + 贪心)

     这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...

  5. 紫书 例题8-17 UVa 1609 (构造法)(详细注释)

    这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上 ...

  6. 紫书 例题 9-5 UVa 12563 ( 01背包变形)

    总的来说就是价值为1,时间因物品而变,同时注意要刚好取到的01背包 (1)时间方面.按照题意,每首歌的时间最多为t + w - 1,这里要注意. 同时记得最后要加入时间为678的一首歌曲 (2)这里因 ...

  7. UVA489 - Hangman Judge【紫书例题4.2】

    题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #inc ...

  8. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  9. 紫书 例题 10-26 UVa 11440(欧拉函数+数论)

    这里用到了一些数论知识 首先素因子都大于M等价与M! 互质 然后又因为当k与M!互质且k>M!时当且仅当k mod M! 与M!互质(欧几里得算法的原理) 又因为N>=M, 所以N!为M! ...

  10. 紫书例题-Ancient Cipher

    Ancient Roman empire had a strong government system with various departments, including a secret ser ...

随机推荐

  1. GDI 像素(5)

    RGB 颜色 使用 RGB 宏可以创建一个由三个整数值(R.G.B)的 COLORREF 值. COLORREF RGB( BYTE byRed, // 红色值(R) BYTE byGreen, // ...

  2. [SCOI2016]萌萌哒(倍增+并查集)

    当区间\([a,b]\)和\([c,d]\)对应相等时. 我们把两个区间对应位置上的数所在并查集合并. 最后并查集的数量为\(num\)答案就是\(9*10^num\)因为是个数,不能有前置\(0\) ...

  3. 训练1-S

    给出N个正整数,检测每个数是否为质数.如果是,输出"Yes",否则输出"No". Input 第1行:一个数N,表示正整数的数量.(1 <= N < ...

  4. Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存

    Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存 参考:<linux编程从入门到精通>,<Linux C程序设计大全>,<unix环境高级编程> ...

  5. 非阻塞IO函数

    关于效率的优化:

  6. Android通过泛型简化findViewById类型转换

    曾经老用findViewById,每次使用还得add cast一下今天看到一个视频(依据视频中使用的IDE判断,应该是几年前的视频了..),使用了一个方法,能够不用每次使用findViewById都去 ...

  7. Android顶部粘至视图具体解释

    不知从某某时间開始,这样的效果開始在UI设计中流行起来了.让我们先来看看效果: 大家在支付宝.美团等非常多App中都有使用.要实现这个效果,我们能够来分析下思路: 我们肯定要用2个一样的布局来显示我们 ...

  8. centos cmake 升级

    本以为升级cmake很简单 下载了最新的(3.15),./configure 没问题 make的时候,提示 openssl.c: undefined symbol openssl, openssl-d ...

  9. MVC 全局异常处理(适用多人操作)

    自定义特性: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

  10. ASP.NET MVC+Bootstrap分页Helper

    <div class="pagination"> <ul> //************分页HTML********* </ul> </d ...