UVA 401 - Palindromes(字符串)

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

  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;
}


【白书之路】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 阅读详情

相关推荐

『杭电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

漠宸离若的博客 454

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 608

算典03_例题_03_HDU-1318

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

duaduac.com 527

python处理镜像字符串

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

z_erduo的博客 2424

Palindromes UVa401 字符串

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

operator456的专栏 474

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

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

不慌不忙、不急不躁 1703

UVa 401 Palindromes(简单字符串

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

huatian5的博客 1961

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 862

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 4770

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的刷题空间 829

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

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

Deng's site \# 1560

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所示(空白项表示该字符镜像后不能得到一个合法字符)。 输入的每行包含一个字符串(保证只有上述字符。不含空白字符),判断它是...

逐梦者 309

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"

天道酬勤 814

UVa 401 Palindromes 字符串基础

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

Jianquan520的专栏 209

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 1374
上一篇: 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、付费专栏及课程。

余额充值