UVA 401 Palindromes
2015-08-21 14:14
441 查看
Palindromes
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.
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.
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
Sample Output
题意:
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对比
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
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.
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 |
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 |
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>//isalpha const 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; }
相关文章推荐
- 如何使用Java、Servlet创建二维码
- C语言多级指针的使用
- jsp布局中关于<iframe>标签的使用
- android 5.0 Material Design酷炫风格的开源项目集合
- (技术前沿)Xcode6 矢量图pdf取代png
- [solr] - solr5.2.1环境搭建 - 使用tomcat做为容器
- C#多线程编程实例 螺纹与窗口交互
- How To Build Compelling Stories From Your Data Sets
- 快速找到Office应用程序安装路径
- greenDao_2.0.0学习笔记3-Hello World
- Spring mvc 的基本使用说明
- xStream完美转换XML、JSON
- 使用Unity3D的50个技巧:Unity3D最佳实践
- Android C层如何加载.so库文件
- LeetCode--delete/merge sorted list
- Spring Dependency Injection (DI)
- ORA-01034: ORACLE not available
- 今目标文荣演讲:主线+连接一切的力量
- Java 堆排序
- HBase表设计——Column Family列族的设计数量不宜过多