字符串训练 ------- 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 阅读详情

相关推荐

【CIC-IDS数据集+机器学习】实现网络流量异常检测

本项目基于CIC-IDS数据集,使用多种机器学习算法实现网络流量异常检测系统。项目采用了完整的机器学习工作流程,从数据预处理到模型部署,实现了高精度的网络入侵检测。

XiaoMu_001的博客 1934

算典03_例题_03_HDU-1318

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

duaduac.com 528

Xilinx System Generator多速率系统(Multi-Rate Systems)的使用

在本实验练习中,您将学习在System Generator中如何使用多个时钟域有效地实现具有多个数据速率的设计。

白码王子小张的博客 1092

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

告别Qweb!用ReportBro在Odoo 13-19版本中5步搞定动态报表

本文介绍了如何在Odoo 13-19版本中使用ReportBro替代Qweb快速实现动态报表设计。通过5步集成指南,包括环境准备、前端集成、后端服务搭建等,展示了ReportBro在可视化设计、即时预览和多格式输出(PDF/XLSX)方面的优势,显著提升开发效率和报表灵活性。

mac99的博客 799

Elsevier期刊LaTeX双栏模板(cas-dc)实战:从Overleaf配置到投稿全流程

本文详细介绍了Elsevier期刊LaTeX双栏模板(cas-dc)在Overleaf平台上的配置与使用全流程,包括模板结构解析、标题与作者信息规范、摘要与关键词特殊格式、正文写作技巧、参考文献管理以及投稿前检查清单。特别针对Elsevier期刊投稿需求,提供了从模板安装到最终投稿的实用指南,帮助研究者高效完成论文排版工作。

weixin_28455801的博客 1323

python处理镜像字符串

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

z_erduo的博客 2425

Fluent UDF实战:除了速度入口,你的DEFINE_PROFILE宏还能搞定这些边界条件(温度、组分、壁面接触角全解析)

本文深入解析Fluent UDF中DEFINE_PROFILE宏在复杂边界条件中的高阶应用,涵盖温度场、组分浓度和壁面接触角等关键场景。通过实战代码示例,展示如何实现空间梯度温度场、动态组分控制和接触角动态调整,助力CFD工程师突破标准界面限制,提升仿真精度和效率。

weixin_28688385的博客 448

第二题 UVa4 401 Palindromes

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

苦鬼·。 178

别再纠结Dify了!实测对比RAGFlow和Dify,聊聊企业知识库到底该怎么选

本文深度对比了RAGFlow和Dify在企业知识库选型中的实际表现,从技术架构、性能指标、部署成本等多维度进行分析。RAGFlow在复杂文档处理和准确率方面表现突出,适合有专职技术团队的企业;而Dify则以低门槛和快速部署见长。文章提供了六维度评估法,帮助企业根据文档复杂度、准确率要求等技术指标做出明智选择。

weixin_30897233的博客 669

VAY 是 SAP 自动科目确定(OBYC-GBB)中的科目修改码,专用于带科目分配对象的销售订单发货场景,核心是触发 “Dr 成本要素科目(如销售费用 / 特定成本对象) Cr 库存商品” 的分录,

摘要:VAY是SAP中用于带科目分配对象(如成本中心、WBS)的销售订单发货的科目修改码,与标准VAX场景不同,它生成"借成本要素科目/贷库存商品"的分录。配置路径为OBYC-GBB-VAY,需确保借方科目为成本要素。典型业务场景包括免费样品、项目专用发货等。常见问题包括VAY未触发或科目记账错误,需检查销售订单科目分配、移动类型设置及OBYC配置。特殊场景建议单独配置科目以便费用分析。

金牌架构师 1252

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

【OpenClaw企业级智能体实战】第04篇:OpenClaw成本优化实战——Token消耗降96%!claude-mem+OpenViking从入门到精通

OpenClaw作为企业级智能体框架,凭借强大的自动化能力成为企业数字化转型的热门工具,但原生机制导致的上下文冗余问题,让众多用户面临“Token消耗失控”的困境——单周账单数千元的案例屡见不鲜。本文基于阿里云实测数据与开源工具官方文档,先深度拆解OpenClaw成本黑洞的核心成因(记忆碎片化、Token指数级膨胀),再系统讲解两款核心优化工具(claude-mem单Agent记忆管理、OpenViking多Agent集群底座)的底层原理、算法架构与实现逻辑,提供从环境搭建、工具集成、参数调优到安全部署

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 702

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

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

A. Prefix and Suffix Array

补题

Selfishness_x的博客 429

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

镜像字符串

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

weixin_30635053的博客 1109

Statistics and Machine Learning Toolbox

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

例题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、付费专栏及课程。

余额充值