UVA401 第一个编程语言博客纪念一下
来源:互联网 发布:四川农大网络教育专业 编辑:程序博客网 时间:2024/05/21 12:46
题目:
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.
Hint
use the C++'s class of string will be convenient, but not a must
就是判断回文和镜像,对于镜像的判断,我是先过滤一遍有没有不符合镜像的字符,然后再判断符不符合镜像的要求。
<span style="font-family:FangSong_GB2312;font-size:18px;">#include<stdio.h>#include<string.h>//判断是否为回文char str[1000];int ispalindrome(){int i;int j;int z=strlen(str);for(i=0,j=z-1;i<j;i++,j--){if(str[i]!=str[j]){return 0;}}return 1;}int ismirrored(){int i;int z=strlen(str);int j=z/2;for(i=0;i<z;i++){ if(str[i]=='B'||str[i]=='C'||str[i]=='D'||str[i]=='F'||str[i]=='G'||str[i]=='K'||str[i]=='N'||str[i]=='P'||str[i]=='Q'||str[i]=='R'||str[i]=='4'||str[i]=='5'||str[i]=='6'||str[i]=='7'||str[i]=='9')return 0;}for (i = 0; i < j; i++) {if(str[i]=='A')if(str[z-1-i]!='A')return 0;if(str[i]=='E')if(str[z-1-i]!='3')return 0;if(str[i]=='H')if(str[z-1-i]!='H')return 0;if(str[i]=='I')if(str[z-1-i]!='I')return 0;if(str[i]=='J')if(str[z-1-i]!='L')return 0;if(str[i]=='L')if(str[z-1-i]!='J')return 0;if(str[i]=='M')if(str[z-1-i]!='M')return 0;if(str[i]=='O')if(str[z-1-i]!='O')return 0;if(str[i]=='S')if(str[z-1-i]!='2')return 0;if(str[i]=='T')if(str[z-1-i]!='T')return 0;if(str[i]=='U')if(str[z-1-i]!='U')return 0;if(str[i]=='V')if(str[z-1-i]!='V')return 0;if(str[i]=='W')if(str[z-1-i]!='W')return 0;if(str[i]=='X')if(str[z-1-i]!='X')return 0;if(str[i]=='Y')if(str[z-1-i]!='Y')return 0;if(str[i]=='Z')if(str[z-1-i]!='5')return 0;if(str[i]=='1')if(str[z-1-i]!='1')return 0;if(str[i]=='2')if(str[z-1-i]!='S')return 0;if(str[i]=='3')if(str[z-1-i]!='E')return 0;if(str[i]=='5')if(str[z-1-i]!='Z')return 0;if(str[i]=='8')if(str[z-1-i]!='8')return 0;if(str[i]=='0')if(str[z-1-i]!='0')return 0;}return 1;}int main(){int a;int b;while(scanf("%s",str)!=EOF){a=ispalindrome();b=ismirrored();if(a==0&&b==0) {printf("%s -- is not a palindrome.",str);}if(a==1&&b==0){printf("%s -- is a regular palindrome.",str);}if(a==0&&b==1) {printf("%s -- is a mirrored string.",str);}if(a==1&&b==1){printf("%s -- is a mirrored palindrome.",str);}printf("\n\n");}return 0;}</span>
- UVA401 第一个编程语言博客纪念一下
- 第一个offer,纪念一下
- 纪念大学第一个编程语言 C language
- 纪念一下我的第一个操作系统
- android第一个应用上架,纪念一下
- 第一个PL/SQL过程,纪念一下
- 以此纪念我的第一个博客
- 开通博客了,用第一篇文章纪念一下。
- 第一篇文章纪念一下
- 恢复博客,纪念一下
- 开通博客,纪念一下
- 俺写的第一个javame程序,纪念一下
- 人生的第一个MakeFile贴出来纪念一下
- 纪念一下Android studio的第一个作业
- 第一次写博客,希望写个helloworld纪念一下!
- 第一个专业技术论坛博客,留个纪念
- 开始学UNIX网络编程了,这是我的第一个网络程序:-)要纪念一下
- 其实就是测试一下,第一个博客
- arcgis 9.3 卸载 安装10.1
- igrimace最新安装源地址apt.so/igrimace3
- 【西祠日志】【04】还不错,今天asp基本功能完成了(2015.07.20周一)(第二周)
- Oracle ltrim() rtrim() 函数 常用内置函数的用法
- Android系统启动过程(转载)
- UVA401 第一个编程语言博客纪念一下
- 两个栈实现一个队列
- 内置类型大小 结构体大小计算
- Android onTouch事件与手势操作
- hdu 5285 wyh2000 and pupil
- 12天学好C语言——记录我的C语言学习之路(Day 5)
- 菜鸟的SQL入门
- 兄弟郊游问题
- 欧拉函数简单应用