uva 401
2011-11-20 15:21
155 查看
#include <stdio.h> #include <string.h> #define N 30 char ch[50]="AAE3HHIIJLLJMMOOS2TTUUVVWWXXYYZ5112S3E5Z88";//0、2、4为原字符 int len=strlen(ch); int is_palindrome(char * a) { int i; int ok=1; int n=strlen(a); for(i=0;i<= n/2;i++) if(a[i]!= a[n-1-i]) {ok=0;break;} //no return ok; //ok } int is_mirror(char* a) { char s ; char s2 ; int j,i; int flag; int n=strlen(a); for( i=0;i<n;i++) { flag=1; for(j=0;j<len;j+=2) { if(a[i]==ch[j]) {s[i]=ch[j+1]; flag=0; break;} } if(flag) return 0; //元素未找到,不是 } s[i]='\0'; for(i=0;i<n;i++) s2[i]=s[n-1-i]; s2[i]='\0'; if(strcmp(a,s2)==0) return 1; else return 0; } int main() { // freopen("abc.txt","r",stdin); char a ; while (scanf("%s",a)!=EOF) { if(is_palindrome(a)&&is_mirror(a)) printf("%s -- is a mirrored palindrome.\n\n",a); else if(is_palindrome(a)) printf("%s -- is a regular palindrome.\n\n",a); else if(is_mirror(a)) printf("%s -- is a mirrored string.\n\n",a); else printf("%s -- is not a palindrome.\n\n",a); } return 0; }
1、
注意:strrev 不能用
Palindromes |
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 |
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
相关文章推荐
- 章三例题3——UVA 401 Palindromes
- uva-401 Palindromes
- UVa 401 - Palindromes
- uva401 - Palindromes结题报告
- uva 401(简单字符处理题)
- UVA 401(palindorme)简单字符串处理
- UVa401
- UVA 401 (13.08.01)
- uva-401 回文词
- UVA 401 Palindromes
- UVa 401 - Palindromes
- UVa 401 Palindromes(镜像回文字符串)
- UVa-401
- 章三例题3——UVA 401 Palindromes
- UVa 401 回文词
- UVA - 401 Palindromes
- UVa 401 Palindromes
- UVa401_Palindromes(小白书字符串专题)
- uva 401
- UVa 401 - Palindromes