Title Description
Input Format
Output Format
Translation of the meaning of problems
The input is a string, the string is determined whether it is a palindromic sequence, and mirror. 00 digital input string is guaranteed to be free. The so-called palindromic sequence, that is, after reversing the original string and the same, and as abbaabba madammadam. The so-called image string, and the original image is left after the same string, such as 2S2S and 3AIAE3AIAE. Note that not every character can get a legal character after the mirror. In this problem, each mirror legal characters shown in the following table:
Character Reverse
A A
E 3
H H
I I
J L
L J
M M
O O
S 2
T T
U U
V V
W W
X X
Y Y
Z 5
1 1
2 S
5 Z
8 8
Sample input and output
Input # 1
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
Output # 1
NOTAPALINDROME -- is not a palindrome.
ISAPALINILAPASI -- is a regular palindrome.
2A3MEAS -- is a mirrored string.
ATOYOTA -- is a mirrored palindrome.
code show as below:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<cstdio>
using namespace std;
#pragma warning(disable:4996)
int n, l, i, a[10000];
const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[] = {"not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome"};
char r(char ch) {
if (isalpha(ch))return rev[ch-'A'];//是字母,返回反转的字母/数字
return rev[ch-'0'+25];//如果是数字,返回字母(字母26+数字9)
}
int main()
{
char s[30];
while (scanf("%s",s)==1)
{
int len = strlen(s);//计算长度,二分,左边右边相比较
int p = 1,m = 1;//标志
for (int i=0;i<(len+1)/2;i++)//左右相比
{
if (s[i] != s[len - 1 - i])p = 0;//不是回文串
if (r(s[i]) != s[len - 1 - i])m = 0;//不是镜像串
}
printf("%s -- is %s.\n\n",s,msg[m*2+p]);//按格式打印
}
return 0;
}