hdu 1318 Palindromes


タイトルの住所:
http://acm.hdu.edu.cn/showproblem.php?pid=1318
テーマの説明:
Palindromes
Time Limit:2000/1000 MS(Java/Others)    メモリLimit:65536/32768 K(Java/Others)Total Submission(s):590    Acceepted Submission(s):224
Problem Description
A reglar palindrome is a string of numbers or letters is the same forward.For example,the string“ABCDEDCBA”is a palindrome beuse it is the same when string is read from left.the freght。 
A mirrored string is a streing for which hen rerech of the elemens of the ststriing ischaged to its reverse(ii it has a reverse)and the stststreing is read backwards the rerereult isisisthe ororororororinininstinsting.For eeeexple,strererererererererererererererererererererererererererererererererererererererererererererererererererereree e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e ch others'reverses. 
A mirrored palinlindrome is a streing ththat meets the criteriaa reglar palindrome and the critera a mirrorored sting.The ststreing“ATOYOTA”isa mirrored palindrome because aaaaathe striing isisisrereread backrds thethethe stririririririririririririririririririririisisisisisisisisisisisisisisisisrerererererererereread badrdrdrdrdrdrdrdrdrdrdrdrininininininininininininininininininininininininininininininbackwards、the result is the same as the orriginal string.Of course,「A」「T」「O」,and「Y」arall their own reverses. 
A list of all valid characters and their reverses iss as follows. 
Character  Reverse  Character  Reverse  Character  Reverse  

    A         A         M         M         Y         Y

    B                   N                   Z         5

    C                   O         O         1         1

    D                   P                   2         S

    E         3         Q                   3         E

    F                   R                   4

    G                   S         2         5         Z

    H         H         T         T         6

    I         I         U         U         7

    J         L         V         V         8         8

    K                   W         W         9

    L         J         X         X
Note that O(ゼロ)and 0 are consided the same character and therefore ONLY the letter“0”is a valid character. 
 
Input
Input consists of strigs(one per line)each of which will consist of one to wenty valid characters.The will beのinvalid characters in the stings.Your program shuld to the end of file.
 
Output
For each input string,you shuld print the streing starting in column 1 immediately followed by exactly one of the follwing strigs. 
「--is not a palindrome.」 
if the string is not a palindrome and is not a mirrored string 
「--is a reglar 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 spacting exactly as shown in the table able and demont stred 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.
回文列を判断します。
クイズ:
マッピングモデルを作成して、最初の尾が同時に列を走査します。
コード:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
//char - 'A'  -> index   number - '1' + 26
char chars[35]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9'};
char rev_chars[35]={'A',' ',' ',' ','3',' ',' ','H','I','L',' ','J','M',' ','O',' ',' ',' ','2','T','U','V','W','X','Y','5','1','S','E',' ','Z',' ',' ','8',' '};
char in_str[50];
//judge the string is a palindrome
bool is_palindrome()
{
    int i=0,j=strlen(in_str) - 1;
    while(i<j)
    {
        if(in_str[i]!=in_str[j]) return(false);
        i++;
        j--;
    }
    return(true);
}
//judge the string is a mirrored
bool is_mirrored()
{
    int i=0,j=strlen(in_str)-1;
    while(i<=j)
    {
        char l = in_str[i],re_l = '\0',r = in_str[j];
        if(isdigit(l)) re_l = rev_chars[l - '1' + 26];
        else re_l = rev_chars[l - 'A'];
        if(re_l!=' ')
        {
            if(re_l!=r) return(false);
        }
        else return(false);
        i++;
        j--;
    }
    return(true);
}
int main()
{
    while(scanf("%s",in_str)!=EOF)
    {
        printf("%s",in_str);
        if(is_palindrome())
        {
            if(is_mirrored()) printf(" -- is a mirrored palindrome.
"); else printf(" -- is a regular palindrome.
"); } else { if(is_mirrored()) printf(" -- is a mirrored string.
"); else printf(" -- is not a palindrome.
"); } printf("
"); } return(0); }