题目链接: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): 657 Accepted Submission(s): 250 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. Source
South Central USA 1995
*/ #include <cstdio>
#include <cstring>
#include <cctype>
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);
int p = , m = ;
for(int i = ; i < (len+)/; i++){
if(s[i] != s[len-i-]) p = ;
if(r(s[i]) != s[len-i-]) m = ;
}
printf("%s -- is %s.\n\n", s, msg[m*+p]);
}
return ;
}

hdu 1318 Palindromes(回文词)的更多相关文章

  1. HDU 1544 Palindromes(回文子串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. ...

  2. UVa-401 Palindromes回文词

    虽然是水题,但是容易错.参照了紫书的代码可以写的很简洁.主要还是注意常量数组的使用,能让代码变得简单许多 #include <iostream> #include <cstdio&g ...

  3. 401 Palindromes(回文词)

      Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as ba ...

  4. 回文词 (Palindromes,Uva401)

    例题 3-3 回文词 (Palindromes,Uva401) 输入一个字符中,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有 ...

  5. CSU 1328: 近似回文词

    省赛的A题...现场都没什么人做...其实就一暴力水题......坑死了... 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1 ...

  6. 字符串 - 近似回文词 --- csu 1328

    近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...

  7. csuoj 1328: 近似回文词

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 1 ...

  8. Vijos1327回文词【动态规划】

    回文词 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得到的 结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个回文词.你的任务是写 一个程序,求出将给定字符 ...

  9. 回文词_KEY

    回文词 (palin.pas/c/cpp) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...

随机推荐

  1. css常用知识

    1.基本语法规范p {color:#ff0000;background:#ffffff}a.其中"p"称为"选择器"(selectors),指明我们要给&quo ...

  2. 【译文】漫谈ASP.NET中的Session

    最近这两天被一个Web Farm环境下的Session处理问题虐得很痛苦,网上到处找解决方案,在无意中翻看到这篇文章,感觉很不错,顺手查了一下,貌似没有现成的译文,于是一咬牙一跺脚把这篇文章翻译出来了 ...

  3. cocos2d-x android 字体的设置

    我们知道 ios 自带的字体 和 android 自带的字体不同 为了使我们开发的游戏中的字体统一 我们就需要自己的字体(包括从mac 拷贝出来的 字体) 从 mac 中 copy 出 Thonbur ...

  4. c#如何在win7下设置IE代理的完美解决方案

    有人还发现:在window7下, 在一个进程中, 设置和取消不能都执行,---- 要么设置,要么取消. 但如果第一次运行时,只进行设置代理,退出后再进运行,只进行取消,这是没有问题的.  简单说说中医 ...

  5. F - Tree

    Description You are to determine the value of the leaf node in a given binary tree that is the termi ...

  6. [经典算法] 排列组合-N元素集合的所有子集(二)

    题目说明: 给定一组数字或符号,按照字典序产生所有可能的集合(包括空集合),例如给定1 2 3,则可能的集合为:{}.{1}.{1,2}.{1,2,3}.{1,3}.{2}.{2,3}.{3}. 题目 ...

  7. 【Mood-12】Android开发相关书籍推荐

    新年伊始,找到Android进阶干货若干,2015拜读. 1.Android应用UI设计模式 目前,谷歌Android操作系统在移动市场中风头正劲,并且未来发展势不可挡.<Android应用UI ...

  8. iOS UIimage初始化时的两种方法

    第一种方式:UIImage *image = [UIImage imageNamed:@"image"]; 使用这种方式,第一次读取的时候,先把这个图片存到缓存里,下次再使用时直接 ...

  9. Zendstudio 9.0.2 安装Aptana3 并且配置 jQuery

    Zendstudio 9.0.2 安装Apnata3 并且配置 jQuery aptana-javascript-jquery.ruble文件夹下载地址: http://dl.dbank.com/c0 ...

  10. 给力的轻量级JavaScript动画框架 - jsMorph

    jsMorph 是一个独立的轻量级 JavaScript 动画框架,可以用它来操纵多个 HTML 元素的样式,实现动画效果.此框架会自动检测起始位置.转换单位.调整渲染的速度,以此来获得更流畅的渲染体 ...