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 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 |
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.
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
NOTAPALINDROME -- is not a palindrome.
ISAPALINILAPASI -- is a regular palindrome.
2A3MEAS -- is a mirrored string.
ATOYOTA -- is a mirrored palindrome.
【注意】:
题目意思:
判断输入的字符串是否是回文串还是镜面字符串。
回文串:从左到右读和从右到左读是一样的。
镜面字符串:如果某个字符有镜面字符,转换为相应的镜面字符。转换后从左到右读和从右到左读是一样的。
数字0和字母O是等价的。
【代码】:
-
-
-
-
-
-
-
-
-
-
#include<stdio.h>
-
#include<string.h>
-
-
charMirroredStr[]={'A','','','','3','','','H',
-
'I','L','','J','M','','O','','','','2','T','U','V','W','X','Y','5'};
-
charMirroredNum[]={'1','S','E','','Z','','','8',''};
-
-
intIsPalindromes(charStr[]){
-
inti,j;
-
for(i=0,j=strlen(Str)-1;i<j;i++,j--){
-
-
if((Str[i]=='0'&&Str[j]=='O')||(Str[i]=='O'&&Str[j]=='0')){
-
continue;
-
}
-
if(Str[i]!=Str[j]){
-
return0;
-
}
-
}
-
return1;
-
}
-
-
intIsMirrored(charStr[]){
-
chartemp[21];
-
inti,j,index;
-
intlen=strlen(Str);
-
for(i=0,j=len-1;i<len;i++,j--){
-
if(Str[i]>='A'&&Str[i]<='Z'){
-
index=Str[i]-'A';
-
temp[i]=MirroredStr[index];
-
}
-
else{
-
index=Str[i]-'1';
-
temp[i]=MirroredNum[index];
-
}
-
-
if((temp[i]=='0'&&Str[j]=='O')||(temp[i]=='O'&&Str[j]=='0')){
-
continue;
-
}
-
if(temp[i]!=Str[j]){
-
return0;
-
}
-
}
-
return1;
-
}
-
intmain(){
-
charStr[21];
-
inti,len,IsP,IsM;
-
-
while(scanf("%s",Str)!=EOF){
-
len=strlen(Str);
-
printf("%s--",Str);
-
-
IsP=IsPalindromes(Str);
-
-
IsM=IsMirrored(Str);
-
-
if(IsP==0&&IsM==0){
-
printf("isnotapalindrome.\n");
-
}
-
elseif(IsP==1&&IsM==1){
-
printf("isamirroredpalindrome.\n");
-
}
-
elseif(IsP==1&&IsM==0){
-
printf("isaregularpalindrome.\n");
-
}
-
elseif(IsP==0&&IsM==1){
-
printf("isamirroredstring.\n");
-
}
-
printf("\n");
-
}
-
return0;
-
}
-
-
分享到:
相关推荐
判断输入字符串是否为镜像或回文串。 来源于UVaOJ - 401. 水题。
-palindromes-源码.rar
CIS 241回文 CIS 241中的作业4(第2部分)中的第2个 到期日: 2020年10月23日 程序说明: 回文是指向前和向后以相同方式拼写的字符串。 回文症的一些例子是:“雷达”,“可能是我看到的厄尔巴岛”,以及,如果您...
选择以下选项之一: 从下载最新的稳定版本,或使用创建自定义版本。 克隆git repo- git clone https://github.com/h5bp/html5-boilerplate.git并签出您要使用的带。 特征 HTML5准备好了。 放心使用新元素。 设计...
USACO题目Dual Palindromes (dualpal)及代码解析
zoj 1325 Palindromes.md
poj 3376 Finding Palindromes.md
在网络浏览器中打开palindromes.html 使用的技术 使用HTML和JavaScript创建 合法的 版权所有(c)2015 Chris Swan和Phillip Shannon 该软件已获得MIT许可。 特此免费授予获得此软件和相关文档文件(“软件”)副本...
回文 简单的回文解析应用程序,给出了前三个最大的回文 说明:mvn install在目标/文件夹中运行具有一个参数的应用程序以扫描回文(将列出第一个)
题目有 Beautiful Meadow Big String Outspread Image Transformation palindromes Sum Up
ACM题目及答案——Common permutation,Base 9 Calculator,Calendar,Sorting by Swapping,Palindromes
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
数据结构和算法模拟面试学习指南... 输入: "Dad gave mom a Tesla as a racecar" 输出: Dad, mom, racecar, 3 Palindromes 解释哈希表如何工作。 给定2个链表,其中每个链表中的每个节点代表一个字符串中的一个字符,
2001 计算两点间的距离 2005 第几天? 2007 平方和与立方和 2010 水仙花数 2011 多项式求和 2012 素数判定 2013 蟠桃记 2018 母牛的故事 ...2029 Palindromes_easy version 2035 人见人爱A^B 2040 亲和数
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings “pop”, “noon”, “x”, ...
ZJU_Main 主页 下一页 ZJU 题型分类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 1045 HangOver 简单题 ... 1049 I Think I Need a Houseboat 简单题 ...
ZJU 题型分类 ZJU_Main 主页 下一页 ZJU 题型分类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 ... 1049 I Think I Need a Houseboat 简单题 ...
标题前言hdu2023求平均成绩hdu2027统计元音hud2044一只小蜜蜂…hud2029Palindromes _easy versionhud2043密码hud2040亲和数hud2021发工资咯hud2032杨辉三角 前言 今天bigsai陪伴我刷题,我很高兴在他的帮助下过了8道...