UVA 401 Palindromes
来源:互联网 发布:快递数据接口 编辑:程序博客网 时间:2024/06/16 19:48
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
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>//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;}
- UVa 401 Palindromes
- UVa OJ 401-Palindromes
- UVa:401 - Palindromes
- uva 401 Palindromes //字符串
- uva 401 - Palindromes
- UVa 401 - Palindromes
- UVa 401 - Palindromes
- UVa 401 - Palindromes
- uva-401 - Palindromes
- UVa 401 Palindromes
- uva 401 Palindromes
- uva 401 Palindromes
- UVA 401 - Palindromes
- UVa 401 - Palindromes
- UVA 题目401 - Palindromes
- UVA 401 Palindromes
- UVa 401: Palindromes
- UVA 401 Palindromes
- Android.mk
- CRB and Candies(lcm(C(n,0)..C(n,n)=lcm(1,2,,,n+1)/(n+1)))hdu5407
- Maven + Spring hello world example
- 如何通过PS把LOGO的背景色变透明
- Qt-提升界面程序的可读性
- UVA 401 Palindromes
- UFLDL教程(一)---稀疏自编码器
- ViewPager滑动监听
- springmvc项目jsp页面传递参数至controller中文乱码解决方案
- Linux时间子系统之(二):软件架构
- Android Volley完全解析(一),初识Volley的基本用法
- Android笔记(九)尺寸和单位
- 【POJ 2115】 C Looooops (扩展欧几里德)
- android 获取通讯录并显示listview