Contest4:Problem B: Mirror Expression

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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值