PalindromesTime
limit:MS
Memory Limit:0KB
64bit IO Format:%lld & %llu SubmitStatus
Description
A regular palindrome is a string of numbers or letters so is the same forward as backward. For example, the string "abcdedcba" was a palindrome because it was the same when the string was read from The left-to-right as-is-string is-read from-right-to-left.
A mirrored string is a string for which when each of the elements of the string was changed to its reverse (if it had a rev Erse) and the string is read backwards the result is the same as the original string. For example, the string "3AIAE" was 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 St Ring. The string " atoyota " is a mirrored palindrome because if the string is read backwards, the Strin The same as the original and because if each of the characters are replaced by their reverse and the result is a read back Wards, the result is the same as the original string.
Of course, "A", "T" , "O" , and "Y" Is all their own reverses.
A List of all valid characters and their reverses are 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 |
|
|
Note that O (zero) and 0 (the letter) is considered the same character and therefore only the "0 "is a valid character.
Input
Input consists of strings (one per line) each of the which would consist of one to twenty valid characters. There'll be is 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 FOLLOWI ng 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 was 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 |
Note The output line was to include the -' s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.
In addition, after the output line, you must print a empty line.
Sample Input
Notapalindrome Isapalinilapasi 2a3meas Atoyota
Sample Output
Notapalindrome Isapalinilapasi 2a3meas Atoyota --is a mirrored palindrome.
Hint
Use the C + + 's class of string would be convenient, but not a must
This topic involves two kinds of strings, one is palindrome string, one is a mirror string, palindrome string is the same as before and from the back, the mirror string is after the substitution can be like a palindrome string. A total of four cases: (1) is a palindrome string is also a mirror string (2) is a palindrome string is not a mirror string (3) is a mirror string is not a palindrome (4) is not a mirror string is not a palindrome string. Give you a string to decide what kind of situation you are in.
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm>using namespace Std;char a[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; char b[]= "a 3 HIL JM O 2tuvwxy51se Z 8"; Char Str[1010];int is_p ( Char str[]) {int i; int Len=strlen (str); for (i=0; i< (LEN/2); i++) {if (str[i]!=str[len-i-1]) return 0; } return 1;} int Is_m (char str[]) {int i,j; int Len=strlen (str); if (len==1) {for (i=0; i<35; i++) {if (str[0]==a[i]) break; } if (i==35| | Str[0]!=b[i]) return 0; else return 1; } else if (len>1) {for (i=0, i< (len/2+1); i++) {for (j=0; j<35; J + +) { if (Str[i]==a[j]) break; } if (j==35| | STR[LEN-I-1]!=B[J]) return 0; } return 1; }}int Main () {int flag1,flag2; while (~SCANF ("%s", str)) {flag1=is_p (str); Flag2=is_m (str); printf ("%d%d<<<<<<<", flag1,flag2); if (flag1&&flag2) {printf ("%s--is a mirrored palindrome.\n\n", str); } else if (Flag1&&!flag2) {printf ("%s--is a regular palindrome.\n\n", str); } else if (FLAG2&&!FLAG1) {printf ("%s--is a mirrored string.\n\n", str); } else if (!FLAG2&&!FLAG1) {printf ("%s--is not a palindrome.\n\n", str); }} return 0;}
UVA 401-palindromes (Analog)