ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

寒假练习——Palindromes

2020-01-15 20:03:57  阅读:466  来源: 互联网

标签:palindrome string read 练习 mirrored each Palindromes 寒假 same


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

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.

题目大意:字符串有回文和镜像。回文就是正反都一样,镜像就是按照题目规则替换字母后反转和原字符串一样。题目要去判断提供字符串是什么类型的。

AC代码:

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[50],s3[50],s4[50];
char s1[]="AEHIJLMOSTUVWXZY12358BCDFGKNPQR4679";
char s2[]="A3HILJMO2TUVWX5Y1SEZ8              ";
int main()
{
    while(~scanf("%s",s))
    {
        int flag1=1,flag2=1;
        memset(s3,0,sizeof(s3));
        int l=strlen(s);
        for(int i=0;i<l;i++)
            s3[i]=s[i];//复制原字符串
        for(int i=0;i<l;i++)//判断回文
            if(s[i]!=s[l-i-1])
                flag1=0;
        for(int i=0;i<l;i++)//变换
            for(int j=0;j<35;j++)
                if(s3[i]==s1[j])
                {
                    s3[i]=s2[j];
                    break;
                }
        for(int i=0;i<l;i++)//判断镜像
            if(s[i]!=s3[l-i-1])
                flag2=0;
        if(!flag1&&!flag2)
            printf("%s -- is not a palindrome.\n\n",s);
        else if(flag1&&!flag2)
            printf("%s -- is a regular palindrome.\n\n",s);
        else if(flag2&&!flag1)
            printf("%s -- is a mirrored string.\n\n",s);
        else if(flag1&&flag2)
            printf("%s -- is a mirrored palindrome.\n\n",s);
    }
    return 0;
}

 

 

 

 

 

 

勿忘∮心安 发布了20 篇原创文章 · 获赞 0 · 访问量 173 私信 关注

标签:palindrome,string,read,练习,mirrored,each,Palindromes,寒假,same
来源: https://blog.csdn.net/qq_45309822/article/details/103994043

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有