zoukankan      html  css  js  c++  java
  • UVa 401

    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.

    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 (zero) and 0 (the letter) are considered the same character and therefore ONLYthe 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.
    

    哈,这一题不错,遇到了问题了,下面注释……

    #include "stdio.h"
    #include "string.h"

    char cc[27]={'A',' ',' ',' ','3',' ',' ','H','I','L',' ','J','M',' ','O',' ',' ',' ','2','T','U','V','W','X','Y','5'};
    char digit[11]={' ','1','S','E',' ','Z',' ',' ','8',' '};

    int main()
    {
     char s[25];
     int len,i;
     int rp_ok,mp_ok;

     while(scanf("%s",s)!=EOF)//之前用的是fgets(s,sizeof(s),stdin)!=NULL,用了这个,"\0"之前还有一个"\n",在最后输出地时候,它会自动换行,输出格式与题目要求不符合,之后改成gets(s),但是结果一直是错的,也不太清楚是为什么,改了之后输出才正确

     {
      len=strlen(s);
      rp_ok=1;
      mp_ok=1;
      for(i=0;i<=len/2;i++)
      {
       if(s[i]!=s[len-i-1])
        rp_ok=0;

       if(s[i]>='A'&&s[i]<='Z')
       {
        if(cc[s[i]-'A']==' '||cc[s[i]-'A']!=s[len-i-1])
         mp_ok=0;
       }
       else
       {
        if(digit[s[i]-'0']==' '||digit[s[i]-'0']!=s[len-i-1])
         mp_ok=0;
       }
      }
      if(rp_ok==1&&mp_ok==1)
       printf("%s -- is a mirrored palindrome.\n\n",s);
      if(rp_ok==1&&mp_ok==0)
       printf("%s -- is a regular palindrome.\n\n",s);
      if(rp_ok==0&&mp_ok==1)
       printf("%s -- is a mirrored string.\n\n",s);
      if(rp_ok==0&&mp_ok==0)
       printf("%s -- is not a palindrome.\n\n",s);
      memset(s,0,sizeof(s));
     }
     return 0;
    }

  • 相关阅读:
    php根据时间显示刚刚,几分钟前,几小时前的实现代码
    PHP中获取当前页面的完整URL
    PhpExcel中文帮助手册|PhpExcel使用方法
    洛谷P1781 宇宙总统【排序+字符串】
    洛谷P1579 哥德巴赫猜想(升级版)【水题+素数】
    洛谷P1478 陶陶摘苹果(升级版)【水题】
    洛谷P1002 过河卒【dp】
    51Nod
    排序算法总结(C++)
    UVA1339
  • 原文地址:https://www.cnblogs.com/Shirlies/p/2324180.html
Copyright © 2011-2022 走看看