http://acm.hdu.edu.cn/showproblem.php?pid=1318

Palindromes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 787    Accepted Submission(s): 294

Problem Description
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.

" -- 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.

用到了isalpha(ch)  判断是不是一个英文字符 在头文件cctype里

用到了strlen(s) 统计数组长度,在头文件cstring中

使用常量数组会简化代码

 #include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<cstdio>
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 - '' +];
}
int main()
{
char s[];
while(~scanf("%s",s))
{
int len = strlen(s);
bool p = true;
bool m = true;
for(int i = ;i < (len+)/ ; i++)
{
if(s[i]!=s[len--i]) p = false ;
if(r(s[i])!=s[len--i]) m = false;
}
printf("%s -- is %s.\n\n",s,msg[m*+p]);
} return ;
}

Palindromes的更多相关文章

  1. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

  2. hdu 1318 Palindromes

    Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit                                         ...

  3. dp --- Codeforces 245H :Queries for Number of Palindromes

    Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H M ...

  4. Dual Palindromes

    Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...

  5. ytu 1940:Palindromes _easy version(水题)

    Palindromes _easy version Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 47  Solved: 27[Submit][Statu ...

  6. 回文串+回溯法 URAL 1635 Mnemonics and Palindromes

    题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...

  7. UVA 11584 一 Partitioning by Palindromes

    Partitioning by Palindromes Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  8. 洛谷P1207 [USACO1.2]双重回文数 Dual Palindromes

    P1207 [USACO1.2]双重回文数 Dual Palindromes 291通过 462提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 ...

  9. hdu 1318 Palindromes(回文词)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能 ...

  10. URAL 2040 Palindromes and Super Abilities 2 (回文自动机)

    Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...

随机推荐

  1. 为了CET-4!

    Directions For tiis part,you are allowed 30 minutes to write an essay.Suppose there are two options ...

  2. iView的使用【小白向】

    首先看这篇:构建Vue本地开发环境(现阶段还不知道怎么用CDN的方式做...) 安装iView(WindowsPowershell或cmd下用cnpm) 编辑上一篇博客创建的Vue工程 先到main. ...

  3. 使用 Kafka 和 ELK 搭建测试日志系统(1)

    本文仅供自己学习,不合适转载. 这是两篇文章的第一部分. 1. 安装 ELK 1.1 安装 ElasticSearch 在海航云上创建一个 Ubutu 16.4 虚机,2核4GB内存. (1)执行以下 ...

  4. INITTAB 配置文件

    Inittab 文件详解       init的进程号是1(ps -aux | less),从这一点就能看出,init进程是系统所有进程的起点,Linux在完成核内引导以后,就开始运行init程序. ...

  5. gitlab 远程 定时备份

    =============================================== 2017/11/1_第2次修改                       ccb_warlock 更新 ...

  6. spring boot 遇到 supported setting property http://xml.org/sax/properties/lexical-handler

    解决链接:http://apache-fop.1065347.n5.nabble.com/org-xml-sax-SAXNotSupportedException-thrown-by-FOP-td11 ...

  7. CSS 去掉inline-block间隙的几种方法

    最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...

  8. NestedScrollingParent, NestedScrollingChild 详解

    之前听同事提起过 NestedScrollingView,但是一直没有时间去了解,最近一段时间比较空,才开始去了解.先点开,看 NestedScrollingView 源码: public class ...

  9. Head First设计模式之责任链模式

    一.定义 避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到有对象处理它为止. 主要解决:职责链上的处理者负责处理请求,客户只需要将请求 ...

  10. MySQL 配置文件my.cnf

    转载: MySQL配置文件my.cnf 详解:#BEGIN CONFIG INFO#DESCR: 4GB RAM, 只使用InnoDB, ACID, 少量的连接, 队列负载大#TYPE: SYSTEM ...