题目链接: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. Swift用UIBezierPath来画圆角矩形、自定义多路径图形

    最好的特点就是可以自定义路径,设置圆角和描边都很方便,以下为代码和效果,均在playground中实现 1.首先实现一个圆角矩形,并对此路径描边,为其绘制一个轮廓. 1 2 3 4 5 6 7 8 9 ...

  2. 无需图片,使用CSS3实现圆角按钮[转]

    首先来看看效果:   事例HTML代码: <a href="#" class="button green">button</a> < ...

  3. SignalR的简单实现

    1创建mvc的空项目 2添加文件夹Counters放在里面的类用于封装性能计数器 3创建PerfCounterWrapper类用于封装性能计数器的实体 using System; using Syst ...

  4. NoSQL数据库的分布式算法&&memcache集群的实现

    NoSQL数据库的分布式算法  http://blog.nosqlfan.com/html/4139.html 一致性hash算法在memcache集群中的应用   http://alunblog.d ...

  5. git fetch和git pull之间的区别--转载

    原文地址:http://blog.csdn.net/a19881029/article/details/42245955 git fetch和git pull都可以用来更新本地库,它们之间有什么区别呢 ...

  6. 关键字提取算法之TF-IDF扫盲

    TF-IDF(term frequency–inverse document frequency)是一种用于资讯检索与资讯探勘的常用加权技术.TF-IDF是一种统计方法,用以评估一字词对于一个文件集或 ...

  7. How to setup ELM327 Bluetooth WiFi for Android software Torque

    1.    Install OBDII 2.    Install Android Software Torque a)    Copy software to phone from CD b)   ...

  8. 如何让oracle的select强制走索

    大多数情况下,oracle数据库内置的查询优化策略还是很成功的,但偶尔也有糊涂的时候,即使有索引,也会做全表扫描,可以参考以下语句的写法,强制让select语句使用索引. (注意:走索引不一定是最优的 ...

  9. 剑指Offer17 二叉树的镜像

    /************************************************************************* > File Name: 17_Mirror ...

  10. 剑指Offer45 约瑟夫环

    /************************************************************************* > File Name: 45_LastNu ...