​   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. c#(winform)获取本地打印机

    引用 using System.Drawing.Printing; //代码 PrintDocument prtdoc = new PrintDocument(); string strDefault ...

  2. 【Azure 云服务】如何从Azure Cloud Service中获取项目的部署文件

    问题描述 在历史已经部署的云服务(Azure Cloud Service)中,如何获取到项目在很久以前的部署包文件呢? 解决办法 1)如果部署云服务是通过门户上传部署包到存储账号中,则可以直接从存储账 ...

  3. C# 使用 Index 和 Range 简化集合操作

    C# 使用 Index 和 Range 简化集合操作 Intro 有的语言数组的索引值是支持负数的,表示从后向前索引,比如:arr[-1] 从 C# 8 开始,C# 支持了数组的反向 Index,和 ...

  4. 5G组网方案:NSA和SA

    目录 5G组网的8个选项 独立组网(SA) 选项1 选项2 选项5 选项6 总结 非独立组网(NSA) 选项3系列 选项3 选项3a 选项3x 选项7系列 选项4系列 选项8 演进路线 5G组网的8个 ...

  5. 力扣119. 杨辉三角 II

    原题 1 class Solution: 2 def getRow(self, rowIndex: int) -> List[int]: 3 ans = [1] 4 for i in range ...

  6. HDOJ-1024(动态规划+滚动数组)

    Max Sum Plus Plus HDOJ-1024 动态转移方程:dp[i][j]=max(dp[i][j-1]+a[j],max(dp[i-1][k])+a[j]) (0<k<j) ...

  7. 漏洞复现-CVE-2016-4977-Spring远程代码执行

        0x00 实验环境 攻击机:Win 10 靶机也可作为攻击机:Ubuntu18 (docker搭建的vulhub靶场)(兼顾反弹shell的攻击机) 0x01 影响版本 Spring Secu ...

  8. 解决springMVC https环境 jstlview redirect时变为http请求的问题

    <property name="redirectHttp10Compatible" value="false" />

  9. fianl关键词

    一.final关键字概述 final关键字具有最终或不可改变的含义,可用于修饰类.变量.方法.因此被final修饰的类.变量.方法具有以下特征: --final修饰的类不能被继承: --final修饰 ...

  10. RichText实现动态输入关键字高亮颜色显示

    int a = 0; string[] kc = new string[40] { "private","protected","public&quo ...