博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 401 - Palindromes
阅读量:5061 次
发布时间:2019-06-12

本文共 3807 字,大约阅读时间需要 12 分钟。

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 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.

 

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.

#define RUN#ifdef RUN#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MAXN 21int n = 0;char input[MAXN];map
mymap;void initMap(){ mymap['A'] = 'A'; mymap['E'] = '3'; mymap['H'] = 'H'; mymap['I'] = 'I'; mymap['J'] = 'L'; mymap['L'] = 'J'; mymap['M'] = 'M'; mymap['O'] = 'O'; mymap['S'] = '2'; mymap['T'] = 'T'; mymap['U'] = 'U'; mymap['V'] = 'V'; mymap['W'] = 'W'; mymap['X'] = 'X'; mymap['Y'] = 'Y'; mymap['Z'] = '5'; mymap['1'] = '1'; mymap['2'] = 'S'; mymap['3'] = 'E'; mymap['5'] = 'Z'; mymap['8'] = '8';}bool isPalindrome(char* string){ int validLen = strlen(string); //printf("validLen = %d\n", validLen); for(int i=0; i<=validLen/2; i++){ if(string[i] != string[validLen-1-i]){ return false; } } return true;}bool isMirrorString(char* string){ char temp[MAXN]; strcpy(temp, string); for(int i=0; i
::iterator it = mymap.find(string[i]); if(it != mymap.end()){ temp[i] = it->second; } else{ // We must deal with those chars that we cannot find! temp[i] = '?'; } } for(int i=0; i

转载于:https://www.cnblogs.com/AlgoWing/archive/2013/03/11/3189589.html

你可能感兴趣的文章
软件目录结构规范
查看>>
mysqladmin
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
Android 自定义View (三) 圆环交替 等待效果
查看>>
设置虚拟机虚拟机中fedora上网配置-bridge连接方式(图解)
查看>>
HEVC播放器出炉,迅雷看看支持H.265
查看>>
[置顶] Android仿人人客户端(v5.7.1)——人人授权访问界面
查看>>
Eclipse 调试的时候Tomcat报错启动不了
查看>>
【安卓5】高级控件——拖动条SeekBar
查看>>
ES6内置方法find 和 filter的区别在哪
查看>>
Android入门之文件系统操作(二)文件操作相关指令
查看>>
Android实现 ScrollView + ListView无滚动条滚动
查看>>
java学习笔记之String类
查看>>
UVA 11082 Matrix Decompressing 矩阵解压(最大流,经典)
查看>>
jdk从1.8降到jdk1.7失败
查看>>
硬件笔记之Thinkpad T470P更换2K屏幕
查看>>
【知识库】-数据库_MySQL 的七种 join
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>