题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318

题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串。 表面上看这道题有些复杂,如果能熟练运用字符数组的话,代码也颇为简洁。。

  1. /*Palindromes
  2.  
  3. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
  4. Total Submission(s): 657 Accepted Submission(s): 250
  5.  
  6. Problem Description
  7. 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.
  8.  
  9. 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.
  10.  
  11. 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.
  12.  
  13. A list of all valid characters and their reverses is as follows.
  14.  
  15. Character Reverse Character Reverse Character Reverse
  16.  
  17. A A M M Y Y
  18.  
  19. B N Z 5
  20.  
  21. C O O 1 1
  22.  
  23. D P 2 S
  24.  
  25. E 3 Q 3 E
  26.  
  27. F R 4
  28.  
  29. G S 2 5 Z
  30.  
  31. H H T T 6
  32.  
  33. I I U U 7
  34.  
  35. J L V V 8 8
  36.  
  37. K W W 9
  38.  
  39. L J X X
  40.  
  41. Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.
  42.  
  43. Input
  44. 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.
  45.  
  46. Output
  47. For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.
  48.  
  49. " -- is not a palindrome."
  50. if the string is not a palindrome and is not a mirrored string
  51.  
  52. " -- is a regular palindrome."
  53. if the string is a palindrome and is not a mirrored string
  54.  
  55. " -- is a mirrored string."
  56. if the string is not a palindrome and is a mirrored string
  57.  
  58. " -- is a mirrored palindrome."
  59. if the string is a palindrome and is a mirrored string
  60.  
  61. 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.
  62.  
  63. In addition, after each output line, you must print an empty line.
  64.  
  65. Sample Input
  66. NOTAPALINDROME
  67. ISAPALINILAPASI
  68. 2A3MEAS
  69. ATOYOTA
  70.  
  71. Sample Output
  72. NOTAPALINDROME -- is not a palindrome.
  73.  
  74. ISAPALINILAPASI -- is a regular palindrome.
  75.  
  76. 2A3MEAS -- is a mirrored string.
  77.  
  78. ATOYOTA -- is a mirrored palindrome.
  79.  
  80. Source
  81. South Central USA 1995
  82. */
  83.  
  84. #include <cstdio>
  85. #include <cstring>
  86. #include <cctype>
  87. const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
  88. const char* msg[] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"};
  89. char r(char ch)
  90. {
  91. if(isalpha(ch)) return rev[ch-'A'];
  92. return rev[ch - '' + ];
  93. }
  94.  
  95. int main()
  96. {
  97. char s[];
  98. while(~scanf("%s", s)){
  99. int len = strlen(s);
  100. int p = , m = ;
  101. for(int i = ; i < (len+)/; i++){
  102. if(s[i] != s[len-i-]) p = ;
  103. if(r(s[i]) != s[len-i-]) m = ;
  104. }
  105. printf("%s -- is %s.\n\n", s, msg[m*+p]);
  106. }
  107. return ;
  108. }

hdu 1318 Palindromes(回文词)的更多相关文章

  1. HDU 1544 Palindromes(回文子串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. ...

  2. UVa-401 Palindromes回文词

    虽然是水题,但是容易错.参照了紫书的代码可以写的很简洁.主要还是注意常量数组的使用,能让代码变得简单许多 #include <iostream> #include <cstdio&g ...

  3. 401 Palindromes(回文词)

      Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as ba ...

  4. 回文词 (Palindromes,Uva401)

    例题 3-3 回文词 (Palindromes,Uva401) 输入一个字符中,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有 ...

  5. CSU 1328: 近似回文词

    省赛的A题...现场都没什么人做...其实就一暴力水题......坑死了... 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1 ...

  6. 字符串 - 近似回文词 --- csu 1328

    近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...

  7. csuoj 1328: 近似回文词

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 1 ...

  8. Vijos1327回文词【动态规划】

    回文词 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得到的 结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个回文词.你的任务是写 一个程序,求出将给定字符 ...

  9. 回文词_KEY

    回文词 (palin.pas/c/cpp) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...

随机推荐

  1. NServiceBus

    官方网站:http://docs.particular.net/nservicebus/      NServiceBus 是一个用于构建企业级 .NET系统的开源通讯框架.它在消息发布/订阅支持.工 ...

  2. Linux下的线程

    一.线程的优点 与传统进程相比,用线程来实现相同的功能有如下优点: (1)系统资源消耗低. (2)速度快. (3)线程间的数据共享比进程间容易的多. 二.多线程编程简单实例 #include < ...

  3. Linux服务器集群系统(四)--转

    引用地址:http://www.linuxvirtualserver.org/zh/lvs4.html LVS集群的负载调度 章文嵩 (wensong@linux-vs.org) 2002 年 5 月 ...

  4. Centos7安装杀毒软件ClamAV

    Clam AntiVirus(ClamAV)是免费而且开放源代码的防毒软件,软件与病毒码的更新皆由社群免费发布.目前ClamAV主要是使用在Linux.FreeBSD等Unix-like系统架设的邮件 ...

  5. Nice是如何做iOS客户端架构的?

    一个创业产品的iOS客户端架构到底怎么做呢?现下最有活力的图片社交软件Nice的技术负责人刘诗彬将为我们解答创业产品如何实现iOS客户端架构. 分享人:刘诗彬,毕业于北京邮电大学电子信息科学与技术专业 ...

  6. Data Structure 之 KMC字符串匹配算法

    有关模式函数值next[i]确实有很多版本啊,在另外一些面向对象的算法描述书中也有失效函数 f(j)的说法,其实是一个意思,即next[j]=f(j-1)+1,不过还是next[j]这种表示法好理解啊 ...

  7. 使用post方式提交数据

    post提交代码 public class MainActivity extends Activity { @Override protected void onCreate(Bundle saved ...

  8. 【阿里云产品公测】ACE安装Discuz超详细图文教程

    作者:阿里云用户51干警网 hello.今天我们来在阿里云ACE上安装discuz. 因为本人不喜欢X3.2的版本,这次我使用的是DZX2.5. 首先的是准备工作: 一.申请阿里云ACE内测 http ...

  9. Java、Android中Math详解

    java.math.Math类常用的常量和方法: Math.PI 记录的圆周率 Math.E记录e的常量 Math.abs 求绝对值 Math.sin 正弦函数 Math.asin 反正弦函数 Mat ...

  10. OC 和 swift 小结

    1 什么是 OC 语言? OC 语言即面向对象语言,它扩展了 ANSI C 语言,将 SmallTalk 式的消息传递机制加入到 ANSI C 中.它是苹果 OS 和 iOS 以及相关的 API,Co ...