字符串训练 ------- UVA 题目401 - Palindromes

【白书之路】401 - Palindromes 回文串 镜像串 palindrome  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 stri 阅读详情

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.


CharacterReverseCharacterReverseCharacterReverse
AAMMYY
B N Z5
C OO11
D P 2S
E3Q 3E
F R 4 
G S25Z
HHTT6 
IIUU7 
JLVV88
K WW9 
LJXX  


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.


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

题目分析: 主要就是判断回文字符串和镜像字符串 。。。

AC代码如下: 
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

bool isMirrorString(string resStr) {

	int j= resStr.length()-1;
	const char res[] = "AEHIJLMSTUVWXYZ12358";
	const char cmp[] = "A3HILJM2TUVWXY51SEZ8";
	for (int i=0; i<= resStr.length()/2 ; ++i) {

		int k=0;

		for (; k< strlen(res); ++k) {

			if (resStr.at(i) == res[k]) {

				if (resStr.at(j) != cmp[k])
					return false;
				else
					break;
			} 
		}
		if (resStr.at(i) == '0' || resStr.at(i)== 'O') {

			if (resStr.at(j) == '0' || resStr.at(j)== 'O') {


				--j;
				continue;
			} else 
				return false;

		}

		if (k == strlen(res))
			return false;
		--j;
	}
	
	return true;
}

int main() {
	
	string resStr;
	while (cin>> resStr) {

		bool isPlain = false;
		// 先判断回文字符串

		int j = 0;
		char tmpStr[22] = "";
		for (int i= resStr.length()-1; i >=0; --i) {

			tmpStr[j++] = resStr[i];
		}
		tmpStr[j] = '\0';
		if (tmpStr == resStr)
			isPlain = true;// 回文
		
		// 判断是否镜像
		bool isMirror = isMirrorString(resStr);

		if (isPlain == false && isMirror == false) 
			cout<< resStr << " -- is not a palindrome.";
		else if (isPlain == true && isMirror == false)
			cout<< resStr<< " -- is a regular palindrome.";
		else if (isPlain == false && isMirror == true)
			cout << resStr<< " -- is a mirrored string.";
		else if (isPlain == true && isMirror == true)
			cout<< resStr<< " -- is a mirrored palindrome.";

		cout << endl<<endl;
	}

	return 0;
}





        
『杭电1318』Palindromes 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 r 阅读详情

相关推荐

Vmware虚拟机克隆详解:固定ip + 修改uuid等内容

分两大步 设置固定ip 克隆后修改相关配置 本文引用的其他地方的图片。会附上链接 若侵权,删 一、设置静态ip 先进行虚拟网络的编辑 接下来的操作需要管理员权限。(给权限就完事了) 接下来设置网卡: 网络和共享中心→ 更改适配器设置→VMware Network Adapter VMnet8 -> 右键属性 修改TCP/Ipv4的配置,网上常见是这种,笔者是英文的...

Unknownfuture的博客 9070

算典03_例题_03_HDU-1318

**判断一个字符串是否为回文串和镜像串** **回文串的意思就不用说了,正着反着相等就行了** **镜像串就是根据上面给出的表格将原串转换过去,得到的新的字符串如果和原串是逆过来相等的,它就是镜像串** **这里我觉得对应关系有很多,使用常量数组即可使其对应起来** **结果也保存在常量数组里,方便输出**

duaduac.com 528

LIO-SAM编译ubuntu20.04 Noetic

一、下载二、编译&&解决报错报错如下。

Kenneth666888的博客 689

uva 401

#include #include #define N 30 char ch[50]="AAE3HHIIJLLJMMOOS2TTUUVVWWXXYYZ5112S3E5Z88";//0、2、4为原字符 int len=strlen(ch); int is_palindrome(char * a) { int i; int ok=1; int n=strlen(a); for(i=0;i<

Beyond The Sky 610

如何在INCA中修改标定量的初始值,并刷回控制器

测试过程中,有些时候,标定量来不及修改,这就需要修改标定量的初始值了,又不想打开模型重新编译,因此直接在INCA中修改,然后再刷回控制器,就成了最佳选择,之前也学过,长时间不用,忘记怎么搞了,最近又用到了,这次记录一下,以后用到的时候,就不用在网上东翻西找了。截止到2023年11月24日,共找到了两种方法可以实现修改。

weixin_43406519的博客 4199

瑞芯微RK3588开发板VSCode远程开发全攻略:从SSH配置到插件优化

本文详细介绍了如何在瑞芯微RK3588开发板上配置VSCode远程开发环境。从Ubuntu系统下的SSH服务设置、VSCode Remote-SSH扩展安装,到连接建立、基础工具链部署,再到针对ARM平台的性能优化与调试配置,提供了一套完整的实战指南,帮助开发者高效利用本地资源进行嵌入式开发。

weixin_28831341的博客 621

python处理镜像字符串

题目:将字符串s = 'ABCabcefghbxcmvSF'装换为镜像字符串,例如a转换成z,b转换成y 首先科普一下python有两个函数ord() 跟chr() 以上截图来源菜鸟教程 有了ord函数,就可以知道每个字符对应的ASCII,当然也可以直接百度 由百度可知,小写字符a对应的十进制的ASCII是97,小写z对应的是122,26个字母刚好分成两半 a 97...

z_erduo的博客 2425

半导体功率器件IGBT工艺全流程

本文概述了功率器件IGBT(绝缘栅双极型晶体管)的关键制造流程。主要工艺包括:基板制备、离子注入(B+/P+/P+FS层)、绝缘膜形成与加工(CVD沉积及刻蚀)、沟槽刻蚀、电极形成(Emitter和Collector)等步骤。通过离子注入、化学气相沉积和物理气相沉积等半导体工艺,依次完成器件各功能层的构建,最终形成具备高功率特性的IGBT器件。该流程体现了功率半导体制造中典型的掺杂、薄膜沉积和图形化工艺技术。

750

第二题 UVa4 401 Palindromes

学长说刷够紫书上的100道题目就可以进入ACM队 这是从紫书上的第一道题目 题目大意就是判断字符串是否是 镜像串、回文串、以及镜像回文串 镜像规则由题目给出 VJ给出的原UVa题目的PDF 注意一点就是 对于有奇数个字符的字符串中间的字符也要判断,虽然判断不影响他是不是回文串 但是会影响他是否是镜像串 处理:(len+1)/2 #include<iostream> #includ...

苦鬼·。 178

多模态论文笔记——BLIP

本文详细介绍这几年AIGC火爆的隐藏功臣,多模态模型:BLIP。

haopinglianlian的博客 2453

Virtuoso 中的tech file 详细说明

工艺文件(Techfile)是集成电路设计中的核心配置文件,定义了从晶圆制造到版图验证全流程所需的工艺规则和图层属性。在Cadence Virtuoso平台中,Techfile作为连接设计与制造的桥梁,主要包含以下内容: 图层体系定义 金属层、介质层、多晶硅层等物理图层的编号、名称和显示属性 图层用途(DRAW、MASK等)及图层-用途组合(LPP)的优先级 设计规则约束 几何尺寸规则(最小线宽/间距) 包围和延伸规则 密度规则和特殊工艺规则(如天线效应) 器件定义 MOS管、电阻等器件的图层构成 电学参数

u013620135的博客 8121

uva401 镜像字符串

题意:输入一串字符串,判断是回文字符,还是镜像字符,还是镜像字符,还是两者都不是 首先把所有镜像字符都预处理出来,然后保存到数组里,最后暴力判断即可 #include #include #include #define rep(i, j, k) for(int i = j; i <= k; i++) #define MAXN 50 using namespace std; c

cadongllas的博客 754

贪婪投影三角化算法

贪婪投影三角化算法是一种利用点云数据进行曲面重建的方法。其基本思想是通过迭代地连接点云中的邻近点来生成三角形,从而构建出整个表面。这种方法被称为“贪婪”,因为它在每一步仅考虑当前最优的策略,而不考虑全局的最优性。

twnkie的博客 1567

uva 401 Palindromes

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=342   Palindromes  A regular palindrome is a string of numbers or letter

chenjun5845209的专栏 579

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

A. Prefix and Suffix Array

补题

Selfishness_x的博客 429

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

镜像字符串

镜像字符串:就是根据自己设定的转换表对字符串进行转换。 python中用maketrans来创建字符映射的转换表 str.maketrans(intab, outtab) 第一个参数是字符串,表示需要转换的字符, 第二个参数也是字符串表示转换的目标。两个字符串的长度必须相同,为一一对应的关系。 translate() 方法根据转换表进行创建镜像字符串 str.trans...

weixin_30635053的博客 1109

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

例题3-3 回文词(Palindromes,UVa401)

3-3 例题3-3 回文词(Palindromes,UVa401)输入一个字符串,判断它是否为回文串以及镜像串。输入字符串保证不含数字0。所谓回文串,就是反转以后和原串相同,如abba和madam。所有镜像串,就是左右镜像之后和原串相同,如2S和3AIAE。注意,并不是每个字符在镜像之后都能得到一个合法字符。在本题中,每个字符的镜像如图3-3所示(空白项表示该字符镜像后不能得到一个合法字符)。输入...

qq_23034691的博客 524

UVa401_Palindromes(小白书字符串专题)

Description   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

_nplus 1103

算法题_镜像回文字符串

题目: 判断输入的字符串是不是镜像回文字符串。所谓镜像回文字符串就是字符串和它的倒置字符串每一位都是镜像对应,若是镜像回文字符串,则输出“YES”;若不是,则输出“NO”。 其中镜像关系如下所示: 1<==>11 <==> 11<==>1 2<==>52 <==> 52<==>5 3<==>83 <==&gt...

Rocky Ding相信人工智能、数据科学、商业逻辑、金融工具、终身成长以及顺应时代的潮流会赋予我们超能力。 1245

7-2 镜像字符串

镜像字符串是两个字符序列完全相反的字符串。从键盘录入两个不包含空格的字符串,判断第二个是否为第一个的镜像字符串,是则输出yes,否则输出no.

2302_76949164的博客 955

ACM练习题——镜像字符串(C语言解析)

Description time limit per test : 1 secondtimelimitpertest:1second memory limit per test : 128 megabytesmemorylimitpertest:128megabytes 给出一个由字符 ‘b’,‘d’,‘p’,‘q’ 构成的字符串 S,判断 S 是不是镜像字符串。镜像字符串指 S 经过以下操作后得到的字符串仍为 S : 反转 SS ((例:“bdpq” ⇒ “qpdb” )) 将 ‘b’ 改为 ‘d’,‘

student_hwj的博客 2327

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

古古古古古古 515

字符串回文与镜像

题意:回文———从前往后读与从后往前读字符串相同;镜像———字符串中字符镜像之后和原字符串互逆。0(零)是回文,不是镜像字符,O(欧)既是回文又是镜像字符。 <span style="font-size:18px;">#include <iostream> #include <string.h> #include <string>...

aizhi0169的博客 704

UVA 401 回文词 Palindromes

UVA 401

阿巴阿巴 331

判断一个字符串是否为回文串和镜像串(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 lef

Scarlett_geng的博客 3878

UVA 401 (13.08.01)

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 th

勇哥哥的ACM探险 754
上一篇: 字符串训练 ----------- uva 10361 Automatic Poetry
下一篇: 字符串训练------UVA 409题目 Excuses, Excuses!
Aleks_
博客等级 码龄15年 79粉丝 38原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值