​   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的更多相关文章

  1. uva 401.Palindromes

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. uva 401 Palindromes 解题报告

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

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

     题意  给一个字符串 判定其是否为回文串和镜像串  回文串非常好推断  镜像串对于每个字符用数组保存它的镜像字符即可了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才是镜 ...

  4. UVa 401 - Palindromes 解题报告 - C语言

    1.题目大意 输入字符串,判断其是否为回文串或镜像串.其中,输入的字符串中不含0,且全为合法字符.以下为所有的合法字符及其镜像: 2.思路 (1)考虑使用常量数组而不是if或switch来实现对镜像的 ...

  5. 【例题3-3 UVA - 401】Palindromes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果一个字符没有对应的镜像,那么它对应的是一个空格. 然后注意 aba这种情况. 这种情况下b也要查一下它的镜像是不是和b一样. [ ...

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

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

  8. 【鬼畜】UVA - 401每日一题·猛男就是要暴力打表

    管他什么rev数组,msg数组简化代码 #define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <iostream> ...

  9. Partitioning by Palindromes UVA - 11584 简单dp

    题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...

随机推荐

  1. 必知必会之Java注解

    必知必会之Java注解 目录 不定期更新中-- 元注解 @Documented @Indexed @Retention @Target 常用注解 @Deprecated @FunctionalInte ...

  2. 6. vue组件详解(一)

    主要内容: 1. 组件的基本使用 2. 全局组件和局部组件 3. 父组件和子组件 4. 组件语法糖的写法 5. 组件data关联的写法 6. 父子组件的通信 组件系统是 Vue 的一个重要概念,因为它 ...

  3. Python3+PYQT5 实现并打包exe小工具(2)

    前言:前篇已经通过python代码实现了逻辑,传送门:https://www.cnblogs.com/jc-home/p/14447850.html 现在后篇记录的是打包成exe的方式给项目其他同事使 ...

  4. Python网络编程相关的库与爬虫基础

    PythonWeb编程 ①相关的库:urlib.urlib2.requests python中自带urlib和urlib2,他们主要使用函数如下: urllib: urlib.urlopen() ur ...

  5. fastjson 反弹shell

    目录 如下文章说得很不详细,只是用于记录我的步骤,初次利用的人,建议找别的博客文章学习. 准备一台公网服务器 cd test python -m SimpleHTTPServer 8888 javac ...

  6. createNewFile() 报错 open failed: ENOENT (No such file or directory) 的解决方案

    在写Android应用中使用createNewFile() 遇到open failed: ENOENT (No such file or directory) 错误,在网上查了许多方法,不过都不能解决 ...

  7. 技术基础 | 在Apache Cassandra中改变VNodes数量的影响

    Apache Cassandra中num_tokens的默认值在4.0版本中将会有变化!这看起来好像只是在CHANGES.txt文件中做了个小小的改动,但实际上这个改动将会对集群的日常运维有着深远的影 ...

  8. SpringBoot 开发提速神器 Lombok+MybatisPlus+SwaggerUI

    导读 Lombok:可以让你的POJO代码特别简洁,不止简单在BO/VO/DTO/DO等大量使用,还有设计模式,对象对比等 MybatisPlus:增加版Mybatis,基础的数据库CRUD.分页等可 ...

  9. 主成分分析 | Principal Components Analysis | PCA

    理论 仅仅使用基本的线性代数知识,就可以推导出一种简单的机器学习算法,主成分分析(Principal Components Analysis, PCA). 假设有 $m$ 个点的集合:$\left\{ ...

  10. TextRank算法及生产文本摘要方法介绍

    TextRank 算法是一种用于文本的基于图的排序算法,其基本思想来源于谷歌的 PageRank算法,通过把文本分割成若干组成单元(句子),构建节点连接图,用句子之间的相似度作为边的权重,通过循环迭代 ...