hdu 1318 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): 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(回文词)的更多相关文章
- HDU 1544 Palindromes(回文子串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. ...
- UVa-401 Palindromes回文词
虽然是水题,但是容易错.参照了紫书的代码可以写的很简洁.主要还是注意常量数组的使用,能让代码变得简单许多 #include <iostream> #include <cstdio&g ...
- 401 Palindromes(回文词)
Palindromes A regular palindrome is a string of numbers or letters that is the same forward as ba ...
- 回文词 (Palindromes,Uva401)
例题 3-3 回文词 (Palindromes,Uva401) 输入一个字符中,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有 ...
- CSU 1328: 近似回文词
省赛的A题...现场都没什么人做...其实就一暴力水题......坑死了... 1328: 近似回文词 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1 ...
- 字符串 - 近似回文词 --- csu 1328
近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...
- csuoj 1328: 近似回文词
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 1328: 近似回文词 Time Limit: 1 Sec Memory Limit: 1 ...
- Vijos1327回文词【动态规划】
回文词 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得到的 结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个回文词.你的任务是写 一个程序,求出将给定字符 ...
- 回文词_KEY
回文词 (palin.pas/c/cpp) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...
随机推荐
- AssetsManager下载类
cocos2dx-2.1.3 2dx自己代的例子进行讲解 360 cocos2dx net --> 2.1.3AssetsManager AppDelegate.cpp详解 1.创建目录 ...
- mysql 升级方法
Performing an In-place Upgrade This section describes how to perform an in-place upgrade. Review Bef ...
- 从ext2文件系统上读出超级块
概述 本篇博客中,我们将仔细分析如何从格式化为ext2文件系统的磁盘中读取超级块并填充内存超级块结构,每次将一个格式化了ext2文件系统的磁盘(分区)挂载到挂载点的时候会调用该方 ...
- 在Ubuntu 14.04 64bit上安装numpy和matplotlib库
原文:http://blog.csdn.net/tao_627/article/details/44004541 按照这个成功安装! 机器学习是数据挖掘的一种实现形式,在学习<机器学习实战> ...
- Linux下的lds链接脚本基础
转载:http://soft.chinabyte.com/os/104/12255104.shtml 今天在看uboot引导Linux部分,发现要对链接脚本深入了解,才能知道各个目标文件的内存分布 ...
- selenium python 定位一组对象
为什么定位一组对象? 定位一组对象的思想 在定位一组对象的过程中我们如何实现?以前的都是通过具体的对象定位,那么定位一组我们就需要通过css来定位 在单个定位对象中使用的是find_elem ...
- iOS7开发中的新特性
iOS7到现在已经发布了有一段时间了.相信你现在已经了解了它那些开创性的视觉设计,已经了解了它的新的API,比如说SpirteKit,UIKit Dynamics以及TextKit,作为开发者 ...
- asp.net等项目编译失败的原因之不能写入
本人遇到过一次生成mvc4项目失败,说是不能写入,后发现是权限问题,特此记录. 解决方案: 对C盘下的temp文件夹设置当前用户的写入权限即可.
- iOS 抓取 UIwebview 上 所有 图片 并进行滚动播放
关于在UIwebview上添加滚动图片 两种滚动手势会混淆,应为webview有webview.scrollview的属性 故参照昨天的随笔 scrollview嵌套解决方案. 本篇随笔主要讲循环使用 ...
- mybatis--MapperProxy事务
上篇 详细分析了org.mybatis.spring.mapper.MapperScannerConfigurer 和 org.mybatis.spring.SqlSessionFactoryBean ...