Palindromes

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.

STRING CRITERIA
" -- 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.

输入样例:

NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA

输出样例:

NOTAPALINDROME -- is not a palindrome.

ISAPALINILAPASI -- is a regular palindrome.

2A3MEAS -- is a mirrored string.

ATOYOTA -- is a mirrored palindrome.
大意就是判断一个输入的字符串是否为回文和镜像的,因此我写了两个函数。而对于题中表格的处理,本来开始打算用数组的,后来觉得不方便,改用switch语句了。
题目本来不难,注意特殊情况的处理,就是当字符串长度为1的时候。当n==1时,是回文的,当且仅当改字符和本身是镜像的时候,这个字符串是镜像的。
对了,还有很重要的一点就是每次输出后都要再输出一个空行,对于我们这种英语渣渣是怎么会注意到这种东西的。。
 #include <iostream>
#include <cstring>
using namespace std; const char* res[] = {" -- is not a palindrome.", " -- is a regular palindrome.",
" -- is a mirrored string.", " -- is a mirrored palindrome."}; int main(void)
{
char Reverse(char c);
bool Palindrome(char s[], int n);
bool Mirrored(char s[], int n);
char s[];
int len;
while(cin >> s)
{
len = strlen(s);
bool flag1 = Palindrome(s, len);
bool flag2 = Mirrored(s, len);
cout << s;
if(!flag1 && !flag2)
cout << res[] << endl << endl;
if(flag1 && !flag2)
cout << res[] << endl << endl;
if(!flag1 && flag2)
cout << res[] << endl << endl;
if(flag1 && flag2)
cout << res[] << endl << endl;
}
return ;
}
char Reverse(char c)
{
switch (c)
{
case 'A':
case 'H':
case 'I':
case 'M':
case 'O':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case '':
case '':
return c;
case 'E':
return '';
case 'J':
return 'L';
case 'L':
return 'J';
case 'S':
return '';
case 'Z':
return '';
case '':
return 'S';
case '':
return 'E';
case '':
return 'Z';
default:
return ;
}
}
//判断是否是回文字符串
bool Palindrome(char s[], int n)
{
int i;
if(n == )
return true;
for(i = ; i < n / ; ++i)
{
if(s[i] != s[n - - i])
return false;
}
return true;
}
//判断是否是镜像字符串
bool Mirrored(char s[], int n)
{
int i;
if(n == )
{
if(Reverse(s[]) == s[])
return true;
else
return false;
}
for(i = ; i < n / ; ++i)
{
if(Reverse(s[i]) == )
return false;
if(Reverse(s[i]) != s[n - - i])
return false;
}
return true;
}

代码君

UVa401 回文词的更多相关文章

  1. 回文词 (Palindromes,Uva401)

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

  2. CSU 1328: 近似回文词

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

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

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

  4. csuoj 1328: 近似回文词

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

  5. 401 Palindromes(回文词)

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

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

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

  7. 回文词_KEY

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

  8. csu-1328 近似回文词 和 最长回文字符串

    原博文地址:http://blog.csdn.net/u012773338/article/details/39857997 最长回文子串 描述:输入一个字符串,求出其中最长的回文子串.子串的含义是: ...

  9. CSU 1328 近似回文词【最长回文字符串(三种方法)】

    输入一行文本,输出最长近似回文词连续子串.所谓近似回文词是指满足以下条件的字符串: 1. S以字母开头,字母结尾 2. a(S)和b(S)最多有2k个位置不同,其中a(S)是S删除所有非字母字符并且把 ...

随机推荐

  1. pyhton Chapter3 读文件

    使用内置函数open()打开文件,data=open("1.txt").利用data.close()关闭文件.利用data.readline()读取文件中的一行数据,然后指示读取文 ...

  2. MEAN实践——LAMP的新时代替代方案(下)

    在本系列文章的第一部分旨在介绍一些应用程序的基础技术细节和如何进行数据建模,而这个部分文章将着手建立验证应用程序行为的测试,并会指出如何启动和运行应用程序. 首先,编写测试 首先定义一些小型配置库.文 ...

  3. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  4. cf div2 239 D

    D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. git的安装使用和代码自动部署

    1.安装 http://www.cnblogs.com/sunada2005/archive/2013/06/06/3121098.html http://www.cnblogs.com/zhcncn ...

  6. jstl 的应用 java

    JSTL :JSP Standard Tag Library,JSP标准标签库 1.导入包 jstl.jar standard.jar 2.页面中添加标识 <%@taglib uri=" ...

  7. ExtJs之单选及多选框

    坚持 <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-eq ...

  8. SQL语句AND 和 OR执行的优先级

    例句: ) FROM RT_CUSTALLOCRESULT WHERE REGDATE BETWEEN '2014-03-01' AND '2014-03-31' ) FROM RT_CUSTALLO ...

  9. 知问前端——概述及jQuery UI

    知问系统,是一个问答系统.主要功能:即会员提出问题,会员回答问题.目前比较热门的此类网站有:知乎http://www.zhihu.com.百度知道http://zhidao.baidu.com等.这里 ...

  10. 多项式求ln,求exp,开方,快速幂 学习总结

    按理说Po姐姐三月份来讲课的时候我就应该学了 但是当时觉得比较难加上自己比较懒,所以就QAQ了 现在不得不重新弄一遍了 首先说多项式求ln 设G(x)=lnF(x) 我们两边求导可以得到G'(x)=F ...