Contest4:Problem B: Mirror Expression

来源:互联网 发布:ubuntu16.04 网络映射 编辑:程序博客网 时间:2024/06/05 20:49

Problem B: Mirror Expression

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 217  Solved: 95
[Submit][Status][Web Board]

Description

A mirrored experssion 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 experssion is read backwards the result is the same as the original experssion. For example, the string "3*A+I+A*E" is a mirrored experssion because "A" and "I" are their own reverses, and "3" and "E" are each others' reverses.

A list of all valid characters and their reverses is as follows.

 
Character
Reverse
A
A
B
C
D
E
3
F
G
H
H
I
I
J
L
K
L
J
M
M
N
O
O
P
Q
R
S
2
T
T
U
U
V
V
W
W
X
X
Y
Y
Z
5
1
1
2
S
3
E
4
5
Z
6
7
8
8
9
+
+
-
-
*
*
/
(
)
)
(
Note that 0 (zero) and ‘O’ (the letter) are considered the same character and therefore ONLY the letter ‘O’ is a valid character.

Input

Input consists of strings (one per line) each of which will consist of 2 to 30 valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file (EOF).

Output

For each input string, you should check if it is a mirror expression. If yes, print a word “YES”, else “NO”

Sample Input

A1+N2-35Z-(S1+12)-5ZAE*O-Y-O*3A

Sample Output

NOYESYES

HINT

The total length of the array is 41



#include <stdlib.h>#include <stdio.h>char mirrow(char c){    char d;        if (c=='A')            d='A';        else if(c=='E')            d='3';            else if(c=='I')            d='I';            else if(c=='J')            d='L';            else if(c=='L')            d='J';            else if(c=='M')            d='M';            else if(c=='O')            d='O';            else if(c=='S')            d='2';            else if(c=='X')            d='X';            else if(c=='T')            d='T';            else if(c=='U')            d='U';            else if(c=='V')            d='V';            else if(c=='W')            d='W';            else if(c=='Y')            d='Y';            else if(c=='Z')            d='5';            else if(c=='1')            d='1';            else if(c=='2')            d='S';            else if(c=='3')            d='E';            else if(c=='5')            d='Z';            else if(c=='8')            d='8';                 else if(c=='+')            d='+';                 else if(c=='-')            d='-';                 else if(c=='*')            d='*';                 else if(c=='(')            d=')';              else if(c==')')            d='(';             else if(c=='H')            d='H';            else d='0';return d;}int main(){    int i=0,juge=0,j,k;    char input[42];    while (scanf("%s",&input)!=EOF){     while (input[i]&&juge==0){        if (mirrow(input[i])==0)        juge=1;     i++;}        j=0;        while (juge==0&&j<i){            if (input[i-1-j]!=mirrow(input[j]))                juge=1;        j++;        }    if (juge==0)        printf("YES\n");    else printf("NO\n");    i=0;juge=0;   }   return 0;}


原创粉丝点击