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 阅读详情

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



Miguel Revilla 2001-04-16


=================================

分别判断一下回文字符串和镜像字符串就行了


#include <iostream>
#include <cstring>

using namespace std;

char let[30]={"A   3  HIL JM O   2TUVWXY5"};
char num[10]={"1SE Z  8 "};
char str[22];

int main()
{
    while(cin>>str)
    {
        int pal=1,mir=1;
        int len=strlen(str);
        for(int i=0;i<=len/2;i++)
        {
            if(str[i]!=str[len-1-i])
            {
                pal=0;
                break;
            }
        }
        for(int i=0;i<=len/2;i++)
        {
            if(str[i]>='A'&&str[i]<='Z')
            {
                if(let[str[i]-'A']!=str[len-1-i])
                {
                    mir=0;
                    break;
                }
            }
            else
            {
                if(num[str[i]-'1']!=str[len-1-i])
                {
                    mir=0;
                    break;
                }
            }
        }
        cout<<str;
        if(!pal&&!mir) cout<<" -- is not a palindrome."<<endl;
        if(pal&&!mir) cout<<" -- is a regular palindrome."<<endl;
        if(!pal&&mir) cout<<" -- is a mirrored string."<<endl;
        if(pal&&mir) cout<<" -- is a mirrored palindrome."<<endl;
        cout<<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 阅读详情

相关推荐

SDM量化噪声等效到PLL输出的传递函数推导

在历年文章或书本中少见SDM量化噪声等效到PLL输出的传递函数推导。需了解SDM量化噪声的本质,配合欧拉方程简化,并将Z域转化成S域。最终结合断环处等效到PLL输出的传递函数,方可完成。

u010486560的博客 1407

算典03_例题_03_HDU-1318

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

duaduac.com 529

量子城域网建设设备系列(三):网络管理系统(NMS)

本文对量子网络中的网络管理系统进行了初步的介绍。

量子领域相关话题 2013

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

基于Simulink的自适应反步法(Adaptive Backstepping)控制​

本文针对非线性系统控制中未知参数和强非线性耦合的挑战,提出基于Simulink的自适应反步法解决方案。通过融合参数在线估计与反步递归设计,该方法显著提升了永磁同步电机(PMSM)速度控制的鲁棒性,使跟踪误差从20%降至3%,参数估计收敛时间小于0.5秒。文章详细阐述了从算法推导到Simulink实现的完整流程,包括系统架构设计、核心算法推导(以PMSM为例)、模块化建模方法、参数优化策略以及工程部署建议。提供的自适应控制器MATLAB代码和关键参数表可直接应用于实际工程,为电机驱动、机械臂等非线性系统控制提

xiaoheshang_123的博客 101

AI上推荐 之 逻辑回归模型与GBDT+LR(特征工程模型化的开端)

1. 前言 随着信息技术和互联网的发展, 我们已经步入了一个信息过载的时代,这个时代,无论是信息消费者还是信息生产者都遇到了很大的挑战: 信息消费者:如何从大量的信息中找到自己感兴趣的信息? 信息生产者:如何让自己生产的信息脱颖而出, 受到广大用户的关注? 为了解决这个矛盾, 推荐系统应时而生, 并飞速前进,在用户和信息之间架起了一道桥梁,一方面帮助用户发现对自己有价值的信息, 一方面让信息能够展现在对它感兴趣的用户前面。 推荐系统近几年有了深度学习的助推发展之势迅猛, 从前深度学习的传统推荐模型(协

Miracle8070 8253

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

IP-guard发布新版本4.87.2241.0

IP-guard发布了新版本4.87.2241.0,用户可通过提供的下载地址获取完整安装包和升级包。下载后,用户需联系厂家申请测试序列号以进行安装和使用。IP-guard是一款专注于企业文件加密、文档加密系统、防泄密软件、数据安全的软件。

IP-Guard专栏 1531

Palindromes UVa401 字符串

Root :: Problem Set Volumes :: Volume IV      401 - Palindromes 回文词 我头一回在UVa上写题啊,不知道怎么迅速查询题目。暂时先用这样的格式来标记题目吧。 用字符常量数组来标记镜面字母比较方便啊,这一题提交了4次~  -.-  2次编译错误。 UVa还真是娇气啊。 #include #include #include #

operator456的专栏 476

有效Dk值提取方法的仿真分析

通过本文的仿真对比分析,提取有效Dk值方面,TDR技术在一些固定的场景下,依然有其参考应用价值,而随着VNA功能的不断增强和高精度测量手段的不断更新,双端口Delta-L技术才是主流评估方法,而单端口Delta-L技术则可以作为其降本增效的方案补充。

一只豌豆象的博客 1827

46、聚类算法在智能交通数据分析中的应用

本文探讨了聚类算法在智能交通数据分析中的应用,介绍了K-均值算法、K-中心点算法和基于模型的聚类算法的基本原理及特点,并结合实际交通数据讨论了其应用场景与挑战。通过聚类分析,能够从海量交通数据中发现隐藏模式,为交通管理和规划提供科学依据。文章还展示了具体的案例分析和实现流程,为未来智能交通系统的发展提供了参考。

zz67890的博客 133

UVA401 ​​​​​​​Palindromes【字符串】

Palindromes  UVA - 401  题目传送门 题目大意:给你一个字符串,判断其是回文串还是镜像串。 AC代码: #include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cmath&gt; #include &lt;cstdlib&gt; #inclu...

C++的星空 386

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

uva 401 Palindromes(字符串处理)

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

不慌不忙、不急不躁 1705

VB摄像头监控

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

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

UVa 401 Palindromes(简单字符串)

简单的判断是否是回文串、镜像串,然后自己写的真费劲,没逃掉刘汝佳的书,这里的代码很有技巧性,特别值得学习,额,其实他书上的代码都很精简 Character Reverse Character Reverse Character Reverse A A M M Y Y B   N   Z 5 C   O O

huatian5的博客 1965

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

UVA - 401-Palindromes

题目链接:Palindromes UVA - 401 Palindromes Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu SubmitStatus Description A regular palindrome is a

Never say never 863

uva401 Palindromes 字符串,模拟

没什么难度,但是网上的代码都比较冗长,我模仿刘汝佳写的,这才叫编程之美啊。 ps:输出间空一行,别忘了 #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;

萌即正义的萌新教学 477

UVa 401 - Palindromes

这题是Rujia Liu推荐的第一个字符串题。 题意很容易看懂,就是给出字符串,判断其是否是回文或镜面对称回文。输出有4种情况,给出的表格做了很清楚的说明。 思路:写两个函数,is_palindrome()判断是否是回文串,is_mirrored()判断是否是镜像对称串。

程书画的 BLOG 4775

UVA 401 Palindromes 字符串

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

kdwycz的刷题空间 831

UVa 401 Palindromes(镜像回文字符串)

 题意  给一个字符串 判定其是否为回文串和镜像串  回文串很好判断  镜像串对于每一个字符用数组保存它的镜像字符就行了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才是镜像串 #include #include #include const int N = 35; int l; char s[N], mc[] = "A 3 HIL JM O

Deng's site \# 1565

UVa OJ 401-Palindromes

<br />简单字符串处理:<br />{ Author:wzx961008 Problem:UVa 401-Palindromes Verdict:Accepted Language:PASCAL Run Time:0.024s Submission Date:2011-01-12 01:05:27 } const mirrorchar1:string='ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'; mirrorchar2:strin

Chiwin 538

UVA401 Palindromes【字符串处理】

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

逐梦者 311

Palindromes - UVa 401 字符串处理

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 stri

提比的强行AC 958

uva 401 Palindromes //字符串

Palindromes A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA"

天道酬勤 815

UVa 401 Palindromes 字符串基础

题目链接:http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=19520 题目大意:给你一个字符串,一要你判断是否是回文串;二要把这个字符串的每一个字符按照给定的规则翻转,而然后判断翻转后的字符串是否是原串的逆序。 思路不难,但是有些地方要注意。首先要注意的一个问题是,大写字母O和数字0是一样的。这一点我觉得题...

Jianquan520的专栏 210

UVa 401 Palindromes (字符串匹配)

401 - Palindromes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 A regular palindrome is a string of nu

AC,∑ndless 1378
上一篇: HDU 1848 - Fibonacci again and again(SG)
下一篇: UVA 10010 - Where's Waldorf?(字符串)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值