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) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...
随机推荐
- memached+asp.net 4.0 分布式缓存
由于准备做一个商品站点,希望做一个memached缓存.折腾了一个多星期.本机是存进去取出来为空. 各种办法都试过了,还是不行.最后用同事电脑測试是能够的,然后将DEMO公布到阿里云也是能够的.支持. ...
- Linux文件空洞与稀疏文件 转
1.Linux文件空洞与稀疏文件 2.文件系统数据存储 3.文件系统调试 文件空洞 在UNIX文件操作中,文件位移量可以大于文件的当前长度在这种情况下,对该文件的下一次写将延长该文件,并在 ...
- Linux下判断cpu物理个数、几核
自己服务器的输出 1. 查看物理CPU的个数 #cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 1 2. 查 ...
- 获取div相对文档的位置
获取div相对文档的位置,两个方法 经测试 document.getElementById("btn").getBoundingClientRect() 在IE6下有2像素的bug ...
- c#winform将全局异常抛出,不用大量写try()catch()
一.在program.cs处完善成如下,但是这样后只能抛出主线程(UI)的错误,所以请看第二步 /// 应用程序的主入口点. /// </summary> [STAThread] stat ...
- IOS UIwebView 加载网络图片 使用相对地址
方法一: 在html文件内直接使用file:///user//xx//image.png的绝对路径 注:这样可以显示图片,但是如果在程序目录修改,图片就不能显示 方法二: 在html使用占位符,如:在 ...
- [Java] 内部类总结
内部类是指在一个外部类的内部再定义一个类.内部类作为外部类的一个成员,并且依附于外部类而存在的.内部类可为静态,可用protected和private修饰(而外部类只能使用public和缺省的包访问权 ...
- Callable--创建有返回值的线程
转自:JAVA 笔记 Callable 与 FutureTask:有返回值的多线程 常用的Thread类在run方法执行完之后是没有返回值的,要实现子线程完成任务后返回值给主线程需要借助第三方转存.C ...
- frame,bounds,center分析
采用CGPoint来表示坐标系X,Y位置,创建一个坐标的方式为:CGPoint point=CGPointMake(x,y) CGSize用来表示视图的宽度和高度,可以用CGSizeMake(widt ...
- (ASP.NET)总结MVC中@Html表单用法
1.当type类型是text时:@Html.TextBoxFor(model => Model.Name,new{@style = "width: 50px;", @clas ...