2013秋13级预备队集训练习2 --A - Palindromes
来源:互联网 发布:深圳中广核设计院 知乎 编辑:程序博客网 时间:2024/05/16 08:45
Palindromes
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 thereforeONLY 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>int main(){ int i , j , l , flag1 , flag2; char str[100] , *p_str , *p_strend ; while(scanf("%s",str)!=EOF) { flag1 = 0 ; flag2 = 0 ; p_str = str; l = strlen(str); p_strend = p_str + l -1 ; for(j = 0 ; j <= (l-1)/2 ; j++) { if(*p_str != *p_strend) flag1 = 1 ; if(*p_str == 'A' && *p_strend=='A'); else if(*p_str == 'E' && *p_strend=='3'); else if(*p_str == 'H' && *p_strend=='H'); else if(*p_str == 'I' && *p_strend=='I'); else if(*p_str == 'J' && *p_strend=='L'); else if(*p_str == 'L' && *p_strend=='J'); else if(*p_str == 'M' && *p_strend=='M'); else if(*p_str == 'O' && *p_strend=='O'); else if(*p_str == 'O' && *p_strend=='0'); else if(*p_str == '0' && *p_strend=='0'); else if(*p_str == '0' && *p_strend=='O'); else if(*p_str == 'S' && *p_strend=='2'); else if(*p_str == 'T' && *p_strend=='T'); else if(*p_str == 'U' && *p_strend=='U'); else if(*p_str == 'V' && *p_strend=='V'); else if(*p_str == 'W' && *p_strend=='W'); else if(*p_str == 'X' && *p_strend=='X'); else if(*p_str == 'Y' && *p_strend=='Y'); else if(*p_str == 'Z' && *p_strend=='5'); else if(*p_str == '1' && *p_strend=='1'); else if(*p_str == '2' && *p_strend=='S'); else if(*p_str == '3' && *p_strend=='E'); else if(*p_str == '5' && *p_strend=='Z'); else if(*p_str == '8' && *p_strend=='8'); else flag2 = 1; if(flag1==1 && flag2==1) break; p_strend-- ; p_str++ ; } if(flag1==1 && flag2==1) printf("%s -- is not a palindrome.\n\n", str); else if(flag1==0 && flag2==1) printf("%s -- is a regular palindrome.\n\n", str); else if(flag1==1 && flag2==0) printf("%s -- is a mirrored string.\n\n", str); else printf("%s -- is a mirrored palindrome.\n\n", str); } return 0 ;}
- 2013秋13级预备队集训练习2 --A - Palindromes
- 2013秋13级预备队集训练习1 A - Hashmat the Brave Warrior
- 2013秋13级预备队集训练习3--A - Power of Cryptography
- 2013秋13级预备队集训练习3--B - Ant on a Chessboard
- 2013秋13级预备队集训练习4 --A - The Snail
- 2013秋13级预备队集训练习4 --B - Steps
- 2013秋13级预备队集训练习3 --E - The ? 1 ? 2 ? ... ? n = k problem
- 2013秋13级预备队集训练习2 --C - Automatic Poetry
- 2013秋13级预备队集训练习2 --D - Artificial Intelligence?
- 2013秋13级预备队集训练习2 --H - Immediate Decodability
- 2013秋13级预备队集训练习1 B - Back to High School Physics
- 2013秋13级预备队集训练习1 C - Ecological Premium
- 2013秋13级预备队集训练习1 D - The Decoder
- 2013秋13级预备队集训练习1 E - Kindergarten Counting Game
- 2013秋13级预备队集训练习1 F - Machined Surfaces
- 2013秋13级预备队集训练习1 G - Rotating Sentences
- 2013秋13级预备队集训练习1 H - Marvelous Mazes
- 2013秋13级预备队集训练习1 I - Triangle Wave
- C++获取系统时间的方式
- android user模式下如何替换odex文件
- 毕业论文抄袭率过高不着急,修改过关技巧曝光
- 重新配置php+mysql_nginx
- _WIN32_WINNT 与 LPFN_DISCONNECTEX
- 2013秋13级预备队集训练习2 --A - Palindromes
- sharepoint 读取 list folder
- 每个软件工程师都应该尝试的5件事情
- 二分法求单峰函数最大值
- 云计算笔记
- MySQL CLUSTER(MySQL集群)初步
- 2013秋13级预备队集训练习2 --C - Automatic Poetry
- Android之获取手机屏幕大小
- cocos2dx 学习