Palindromes
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
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.
" -- 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.
ISAPALINILAPASI
2A3MEAS
ATOYOTA
用到了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的更多相关文章
- 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 ...
 - hdu 1318 Palindromes
		
Palindromes Time Limit:3000MS Memory Limit:0KB 64bit ...
 - dp --- Codeforces 245H :Queries for Number of Palindromes
		
Queries for Number of Palindromes Problem's Link: http://codeforces.com/problemset/problem/245/H M ...
 - Dual Palindromes
		
Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...
 - ytu 1940:Palindromes _easy version(水题)
		
Palindromes _easy version Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 47 Solved: 27[Submit][Statu ...
 - 回文串+回溯法 URAL 1635 Mnemonics and Palindromes
		
题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...
 - UVA 11584	一 Partitioning by Palindromes
		
Partitioning by Palindromes Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
 - 洛谷P1207 [USACO1.2]双重回文数 Dual Palindromes
		
P1207 [USACO1.2]双重回文数 Dual Palindromes 291通过 462提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 暂时没有讨论 ...
 - hdu 1318 Palindromes(回文词)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能 ...
 - URAL 2040  Palindromes and Super Abilities 2 (回文自动机)
		
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
 
随机推荐
- tar --打包和压缩
			
tar 参考链接 作用:为linux的文件和目录创建档案,也可以在档案中改变文件,或者向档案中加入新的文件即用来压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的 语法:tar[必要参 ...
 - 解决mysql漏洞 Oracle MySQL Server远程安全漏洞(CVE-2015-0411)
			
有时候会检测到服务器有很多漏洞,而大部分漏洞都是由于服务的版本过低的原因,因为官网出现漏洞就会发布新版本来修复这个漏洞,所以一般情况下,我们只需要对相应的软件包进行升级到安全版本即可. 通过查阅官网信 ...
 - Redis在APP中的应用
			
前言 redis 是内存型数据库,读取data速度远快于mysql和sqlserver,如果将APP中列表信息或者一些常被访问的信息转存至内存上,然后APP通过redis读取内存上的数据,那么APP的 ...
 - Notepad++使用教程
			
Notepad++ 快捷键 大全 Ctrl+C 复制Ctrl+X 剪切Ctrl+V 粘贴Ctrl+Z 撤消Ctrl+Y 恢复Ctrl+A 全选Ctrl+F 键查找对话框启动Ctrl+H 查找/替换对话 ...
 - Linux - Shell常用指令
			
一.文件.目录操作命令 1.ls命令:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示文件属性,包括大小,日期,符号连接,是否可读写及 ...
 - python自动安装mysql5.7
			
python自动安装mysql5.7 python版本:python2.6 centos版本:centos6.9 mysql版本:mysql5.7.19 安装目录路径和数据目录路径都是固定,当然也可以 ...
 - Python并发实践_01_线程与进程初探
			
进程与线程 在多任务处理中,每一个任务都有自己的进程,一个任务会有很多子任务,这些在进程中开启线程来执行这些子任务.一般来说,可以将独立调度.分配的基本单元作为线程运行,而进程是资源拥有的基本单位. ...
 - Linux文件的复制、删除和移动命令
			
cp命令 功能:将给出的文件或目录拷贝到另一文件或目录中,就如同DOS下的copy命令一样,功能非常强大. 语法:cp [选项] 源文件或目录 目标文件或目录 说明:该命令把指定的源文件复制到目 ...
 - Neo4j学习笔记(2)——数据索引
			
和关系数据库一样,Neo4j同样可以创建索引来加快查找速度. 在关系数据库中创建索引需要索引字段和指向记录的指针,通过索引可以快速查找到表中的行. 在Neo4j中,其索引是通过属性来创建,便于快速查找 ...
 - Celery(四)定时任务
			
要定时或者周期性的执行任务,可以使用linux的crontab.Celery也提供了类似的Periodic Tasks功能. Celery beat Celery使用celery beat作为任务调度 ...