uva 401 Palindromes
来源:互联网 发布:淘宝运营正确思路流程 编辑:程序博客网 时间:2024/06/08 13:56
uva 401 Palindromes
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 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.
题目大意:判断一个字符串是不是回文、镜像字符串。
解题思路:逐一判断。
PS:注意!!格式!!少个空格害死人!!O和0是相等不是镜像!!!
#include<stdio.h>#include<string.h>int main() {char ch[200], flag1 = 0, flag2 = 0,flag3 = 0;while (scanf("%s", ch) != EOF) {int len = strlen(ch);flag1 = 0; flag2 = 0; flag3 = 0;for (int i = 0; i < (len + 1) / 2; i++) {if ((ch[i] == 'E' && ch[len - i - 1] == '3') || (ch[i] == '3' && ch[len - i - 1] == 'E')) {flag1++;}if ((ch[i] == 'S' && ch[len - i - 1] == '2') || (ch[i] == '2' && ch[len - i - 1] == 'S')) {flag1++;}if ((ch[i] == 'Z' && ch[len - i - 1] == '5') || (ch[i] == '5' && ch[len - i - 1] == 'Z')) {flag1++;}if ((ch[i] == 'J' && ch[len - i - 1] == 'L') || (ch[i] == 'L' && ch[len - i - 1] == 'J')) {flag1++;}if (ch[i] == ch[len - i - 1] || (ch[i] == '0' && ch[len - i - 1] == 'O') || (ch[i] == 'O' && ch[len - i - 1] == '0')) { if (ch[i] == 'A' || ch[i] == 'T' || ch[i] == 'O' || ch[i] == 'Y' || ch[i] == 'I' || ch[i] == 'W' || ch[i] == 'M' || ch[i] == 'H' || ch[i] == 'X' || ch[i] == 'U' || ch[i] == 'V' || ch[i] == '8' || ch[i] == '0' || ch[i] == '1') {flag3++;}else flag2++;}}if (flag3 == (len + 1) / 2) {printf("%s -- is a mirrored palindrome.\n", ch);}else if (flag1 + flag3 == (len + 1) / 2 || flag1 == (len + 1) / 2) {printf("%s -- is a mirrored string.\n", ch);}else if (flag2 + flag3 == (len + 1) / 2 || flag1 + flag2 == (len + 1) / 2 || flag1 + flag2 + flag3 == (len + 1) / 2 || flag2 == (len + 1) / 2) {printf("%s -- is a regular palindrome.\n", ch);}else printf("%s -- is not a palindrome.\n", ch);printf("\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
- Siggraph 2014 Asia 后记
- rt.jar的源代码的位置
- Ubuntu下Apache SSL的简洁配置方法(HTTPS的实现)
- Where is the way to 5G wireless?
- Struts2—Action
- uva 401 Palindromes
- JavaScript闭包及实现循环绑定事件
- HDU 2051 Bitset
- java语言代理模式
- LEETCODE: Divide Two Integers
- 如何查看当前Ubuntu的版本
- HDU 2057 A + B Again
- Error:Failed to find: com.android.support:support-v4:20.+ 之类的错误解决方案
- 日志-14-12-14