Palindromes UVA - 401
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.

Note that ‘0’ (zero) and ‘O’ (the letter) are considered the same character and therefore ONLY the letter ‘O’ 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.
| 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 |
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.
HINT
regular palindrome 是指输入的字符串和倒序是一样的。
mirrored string 是指将输入的字符船的每一个元素按照要求转换之后的倒序和原来输入的相同。
mirrored palindrome 是指输入的字符串同时满足上面的两个要求。
not a palindrome 什么都不满足。
这里采用的思路是将输入的字符串倒序获得一个字符串,然后转换之后再倒序获得一个字符串。然后将输入的字符串和获得的两个字符串比较,按照规则输出结果。
Accepted
#include<stdio.h>
#include<string.h>
char reverse[40] = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";//转换规则
int main()
{
char s[22];
while (scanf("%s", s) != EOF)
{
int len = strlen(s);
char backward[22];
for (int i = len-1, k = 0;i >= 0;i--, k++) //获得倒序字符串
{
backward[k] = s[i];
}
backward[len] = '\0';
char revchanged[22];
for (int i = 0;i < len;i++) //获得转换的字符串
{
if (s[i] <= 'Z' && s[i] >= 'A')
revchanged[i] = reverse[s[i] - 'A'];
else
revchanged[i] = reverse[s[i] - '1' + 26];
}
revchanged[len] = '\0';
char revbackchanged[22]; //转换之后获得倒序字符串
for (int i = len-1, k = 0;i >= 0;i--, k++)
revbackchanged[k] = revchanged[i];
revbackchanged[len] = '\0';
if (strcmp(s, backward) == 0 && strcmp(s, revbackchanged) == 0) //结果输出
printf("%s -- is a mirrored palindrome.\n\n", s);
else if (strcmp(s, backward) == 0)
printf("%s -- is a regular palindrome.\n\n", s);
else if (strcmp(s, revbackchanged) == 0)
printf("%s -- is a mirrored string.\n\n", s);
else printf("%s -- is not a palindrome.\n\n", s);
}
}
Palindromes UVA - 401的更多相关文章
- uva 401.Palindromes
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- uva 401 Palindromes 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 401 Palindromes(镜像回文字符串)
题意 给一个字符串 判定其是否为回文串和镜像串 回文串非常好推断 镜像串对于每个字符用数组保存它的镜像字符即可了 没有的就是空格 注意若字符串长度为奇数 中间那个字母必须是对称的才是镜 ...
- UVa 401 - Palindromes 解题报告 - C语言
1.题目大意 输入字符串,判断其是否为回文串或镜像串.其中,输入的字符串中不含0,且全为合法字符.以下为所有的合法字符及其镜像: 2.思路 (1)考虑使用常量数组而不是if或switch来实现对镜像的 ...
- 【例题3-3 UVA - 401】Palindromes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果一个字符没有对应的镜像,那么它对应的是一个空格. 然后注意 aba这种情况. 这种情况下b也要查一下它的镜像是不是和b一样. [ ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...
- 【鬼畜】UVA - 401每日一题·猛男就是要暴力打表
管他什么rev数组,msg数组简化代码 #define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <iostream> ...
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
随机推荐
- java: 程序包javax.servlet.http不存在
下载好apache tomcat,将lib目录下的servlet-api.jar导入idea即可
- 手把手教你使用IDEA2020创建SpringBoot项目
一.New Project 二.如图选择Spring Initalizr,选择jdk版本,然后点击Next(注意:SpringBoot2开始至少使用JDK1.8) 三.如图根据自己需要修改,然后点击N ...
- linux系统忘记root的登录密码
参考链接:https://www.jb51.net/article/146541.htm 亲测有效 使用场景 linux管理员忘记root密码,需要进行找回操作. 注意事项:本文基于centos7环 ...
- Fastdfs数据迁移方案
1. 方案背景描述 环境迁移,需要迁移旧环境的fastdfs集群的数据到新环境,由于之前数据迁移仅仅是针对mysql和mongodb,对fastdfs数据的迁移了解甚少,本文档主要是针对fas ...
- 在 c++ 程序中出现CtrIsValidHeapPointer问题
在c++程序中出现CtrIsValidHeapPointer问题, 我发现的原因是申请了大量动态数组但是并没有把他们初始化 为数组赋初始值便可以很好解决这一问题.
- Sapper:迈向理想的 Web 应用框架
扎稳阵脚,再进一步. 注意:原文发表于2017-12-31,随着框架不断演进,部分内容可能已不适用. 给迫不及待的小伙伴们的快速入门:Sapper 文档 和快速模板 starter template ...
- 【ZeyFraのJavaEE开发小知识01】@DateTimeFomat和@JsonFormat
@DateTimeFormat 所在包:org.springframework.format.annotation.DateTimeFormat springframework的注解,一般用来对Dat ...
- Win32Api -- 关闭当前应用
本文介绍Windows系统下使用Win32API获取当前应用并关闭的方法. 思路 使用EnumWindows接口枚举当前窗口; 过滤掉不可用.隐藏.最小化的窗口: 过滤掉子窗口: 通过标题.类名过滤掉 ...
- Caffe介绍与测试及相关Hi35xx平台下caffe yolox的使用参考
这一篇我大概讲讲Caffe框架下MNIST的实现与基于Hi35xx平台下caffe yolox的运用等,供大家参考 1.Caffe介绍与测试 caffe全称Caffe Convolutional Ar ...
- Nginx常见的错误配置
Blog:博客园 个人 翻译自Common Nginx misconfigurations that leave your web server open to attack Nginx是当前主流的W ...