UVA 401 Palindromes

来源:互联网 发布:快递数据接口 编辑:程序博客网 时间:2024/06/16 19:48
Palindromes
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

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.

CharacterReverseCharacterReverseCharacterReverseAAMMYYB N Z5C OO11D P 2SE3Q 3EF R 4 G S25ZHHTT6 IIUU7 JLVV88K WW9 LJXX  


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.

STRINGCRITERIA" -- 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.
 
 
题意:
ASD               不是回文字符串
ASDSA          是回文字符串
2A3MEAS      是镜像字符串    2和3 可变成S 和E
ATATA          是镜像回文字符串
先判断是否是 回文字符串   
再判断是否是 镜像
注意:
1:#include<ctype.h> 是 isalpha的库函数(判断是否为字母)
2:
const char* rev="A 3 HIL J O 2TUVWXY51SE Z 8 ";
char rev[35]     ="A 3 HIL J O 2TUVWXY51SE Z 8 ";
const char* print[]={"not a palindrome.","a regular palindrome.","a mirrored string.","a mirrored palindrome."};
char print[4][50]  =  {"not a palindrome.","a regular palindrome.","a mirrored string.","a mirrored palindrome."};
以上两种表示方法相同
const char*rev=char rev[35]
const char*print=char print[4][50]//后者需要明确标出数据大小4 50
3:一般回文串从i-(len+1)/2对比


#include<stdio.h>#include<string.h>#include<ctype.h>//isalphaconst char* rev="A   3  HIL JM O   2TUVWXY51SE Z  8 ";const char* print[]={"not a palindrome", "a regular palindrome","a mirrored string","a mirrored palindrome"};//char rev[35]="A   3  HIL JM O   2TUVWXY51SE Z 8 ";//两种写法都可以//char print[4][50]={"not a palindrome.","a regular palindrome.","a mirrored string.","a mirrored palindrome."};char r(char ch)//把字母都转换成rev中的字符{    if(isalpha(ch))    {        //printf("~%c",rev[ch-'A']);        return rev[ch-'A'];    }//isalpha判断是否为字母 ch-'A'是该字母的序号A=0 B=1 C=2    else    {        //printf("!%c",rev[ch-'0'+25]);        return  rev[ch-'0'+25];    }//ch-'0'是就是这个数的本身     +25 转到reverse中的后9个部分}int main (void){    char a[40];    while(scanf("%s",a)==1)//scanf成功赋值返回1    {        int n=1;        int m=1;        for(int i=0; i<(strlen(a)+1)/2; i++)        {            if(a[i]!=a[strlen(a)-i-1])            {                m=0;//不是回文串            }            if(r(a[i])!=a[strlen(a)-1-i])            {                n=0;//不是镜像串            }        }        printf("\n%s -- is %s.\n\n",a,print[m+2*n]);//刘汝佳的做法真机智!!!真机智!!!真机智!!!    }    return 0;}


0 0
原创粉丝点击