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 |
Notethat O (zero) and 0 (the letter) are considered the same character and thereforeONLYthe 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 |
Notethat 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.
#define RUN #ifdef RUN #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <vector> #include <list> #include <cctype> #include <algorithm> #include <utility> #include <math.h> using namespace std; #define MAXN 21 int n = 0; char input[MAXN]; map<char,char> 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<strlen(string); i++){ map<char,char>::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<strlen(string); i++){ if(string[i] != temp[strlen(string)-1-i]){ return false; } } return true; } int main(){ #ifndef ONLINE_JUDGE freopen("401.in", "r", stdin); freopen("401.out", "w", stdout); #endif memset(input, 0, sizeof(input)); initMap(); while(scanf("%s", input) != EOF){ //printf("%s\n", input); /* if(isPalindrome(input)){ printf("isPalindrome\n"); } else{ printf("Not Palindrome\n"); } */ if(!isPalindrome(input) && !isMirrorString(input)){ printf("%s%s\n\n", input, " -- is not a palindrome."); } else if(isPalindrome(input) && !isMirrorString(input)){ printf("%s%s\n\n", input, " -- is a regular palindrome."); } else if(!isPalindrome(input) && isMirrorString(input)){ printf("%s%s\n\n", input, " -- is a mirrored string."); } else if(isPalindrome(input) && isMirrorString(input)){ printf("%s%s\n\n", input, " -- is a mirrored palindrome."); } } } #endif
相关推荐
标题中的"UVaOJ-401(Palindromes)"表明这是一个关于解决UVa Online Judge(UVa OJ)上编号为401的编程挑战,该挑战的主题是"Palindromes",即回文串。回文串是指一个字符串无论从前读到后还是从后读到前都是相同的,...
标题中的“-palindromes-源码.rar”暗示了这个压缩包可能包含了一组与回文相关的编程源代码。回文是指一个可以正读也可反读的字符串,例如“madam”、“racecar”或者数字“12321”。在编程中,处理回文的算法通常...
CIS 241回文 CIS 241中的作业4(第2部分)中的第2个 到期日: 2020年10月23日 程序说明: 回文是指向前和向后以相同方式拼写的字符串。 回文症的一些例子是:“雷达”,“可能是我看到的厄尔巴岛”,以及,如果您...
该项目是多年迭代开发和综合社区知识的产物。 它没有强加特定的开发哲学或框架,因此您可以按照自己的方式自由地构建代码。 主页: : 资料来源: : 推特: 快速开始 选择以下选项之一: ...
USACO题目Dual Palindromes (dualpal)及代码解析 USACO题目Dual Palindromes (dualpal)是USACO(USA Computing Olympiad)的一个编程题目,要求编写一个程序,从文件读入两个十进制数N和S,然后找出前N个满足大于S...
zoj 1325 Palindromes.md
poj 3376 Finding Palindromes.md
P1217 [USACO1.5] 回文质数 Prime Palindromes
return (palindromes[beforeIndex - 1], palindromes[beforeIndex]); } } ``` 在这个代码中,我们使用了二分查找算法(`BinarySearch`)来快速定位目标数字周围的回文数。如果目标数字本身就是回文数,我们会返回...
在网络浏览器中打开palindromes.html 使用的技术 使用HTML和JavaScript创建 合法的 版权所有(c)2015 Chris Swan和Phillip Shannon 该软件已获得MIT许可。 特此免费授予获得此软件和相关文档文件(“软件”)副本...
从提供的文件名"Palindromes-master"来看,这是一个Git仓库的主分支,通常包含源代码、资源文件、构建脚本等。要运行这个项目,我们需要进入项目的根目录,并确保已经安装了Maven,因为"mvn install"是一个Maven命令...
palindromes = [num for num in range(start, end + 1) if is_palindrome(num)] print(f"在{start}到{end}之间找到的回文数有:", palindromes) if __name__ == "__main__": main() ``` 这个程序首先获取用户...
这个`check_palindromes_in_dict`函数会遍历字典的每个键值对,对值调用`is_palindrome`函数进行回文检查,如果发现非回文字符串,就打印出相关信息。 总的来说,Python的字符串操作和字典遍历是编程中常见的基础...
- **Palindromes**:回文问题,识别或者构造回文串。 - **Stage II** - **The Right Turn Drivers' Club**:右转弯驾驶员俱乐部问题,可能涉及交通流模拟。 - **Triangles**:三角形问题,与POII中的类似。 - **...
**1.2.5 Dual Palindromes** - **问题描述**:题目要求寻找同时是两个不同进制下的回文数。 - **算法思想**:可以采用枚举法,结合快速幂运算进行进制转换和回文检查。 ##### 第二部分:进阶级题目解析 **2.1.1 ...
- P1217 [USACO1.5]回文质数 Prime Palindromes:这可能涉及判断质数和回文数,循环用于检查数字的性质。 6. **练习题目**: - P5724 【深基 4.习 5】求极差:可能要求计算一组数的最大值和最小值之间的差值,...
HDU 3948 The Number of Palindromes 该题目要求找出长度^5 的不同回文子串个数。该题目使用后缀数组来解决,先将 S 的逆加在 S 的后面,然后遍历后缀数组,找到所有回文子串的个数。 总结来说,字符串题目记录...
palindromes that can be built */ int longestPalindrome (string & s) { int result = 0 ; bool hasOdd = false ; std::unordered_map< char , int > count; for ( char ch: s) { ++count[ch]; } for (std::...
9 [1.2] 双重回文数 Dual Palindromes 10 [1.3] 混合牛奶 Mixing Milk 11 [1.3] 修理牛棚 Barn Repair 12 [1.3] 牛式 Prime Cryptarithm 13 [1.3] 虫洞 wormhole 14 [1.3] 滑雪课程设计Ski Course Design
设计性试验实验指导书,栈和队列, 一、验证性实验 2 实验1:顺序栈的各种基本运算 2 实验2:链栈的各种基本运算 3 实验3:顺序队列的各种基本...实验4:镜像回文(Palindromes) 10 实验5:模拟车间流水线的工作 12