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> ...
随机推荐
- 1079 Total Sales of Supply Chain ——PAT甲级真题
1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...
- 死磕Spring之IoC篇 - BeanDefinition 的解析阶段(XML 文件)
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...
- 音视频+ffmpeg
雷霄骅:https://me.csdn.net/leixiaohua1020 致敬! 1.[总结]视音频编解码技术零基础学习方法 https://blog.csdn.net/leixiaohua102 ...
- 后端程序员之路 57、go json
go自带json处理库,位于encoding/json,里面的test很具参考意义,特别是example_test.go json - The Go Programming Languagehttps ...
- PyQt5之 QTableView 添加复选框(自定义委托)
import sys from untitled import Ui_Form from PyQt5.QtWidgets import QApplication, QWidget, QStyleOpt ...
- 实现Hi3559板载自启动网卡、NFS及Telnet服务
实现Hi3559板载开机自启动网卡.NFS及Telnet服务通过直接在home目录下,编辑.bashrc,vi ~/.bashrc 1 ifconfig eth0 up 2 ifconfig eth0 ...
- PAT-1152(Google Recruitment)字符串+素数
Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况. /** * @Author WaleGarrett * @Date ...
- HDOJ-6666(简单题+模拟题)
quailty and ccpc hdoj-6666 题目很简单,按照题目的意思模拟就行了,排序. #include<iostream> #include<cstdio> #i ...
- SpringCloud里面切换数据源无效的问题
问题描述: 调用链:controller1的接口A->service1的方法A->service2的方法B 方法A开启了事务,且指定了数据库A的数据源 方法B也开启了事务,使用了默认的事务 ...
- 如何在 ASP.Net Core 中使用 Lamar
ASP.Net Core 自带了一个极简的 开箱即用 的依赖注入容器,实际上,你还可以使用第三方的 依赖注入容器 来替代它,依赖注入是一种设计模式,它能够有效的实现对象之间的解耦并有利于提高单元测试和 ...