1227: Encoder and Decoder

 1227: Encoder and Decoder


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout3s8192K753289Standard

Being in charge of the computer department of the Agency of International Espionage, you are asked to write a program that will allow a spy to encode and decode their messages.

You can assume a spy's message is at most 80 characters long, and it includes all the upper and lowercase letters of the alphabet plus the space, and any of the following characters:

 

!  ,  .  :  ;  ?

The following is an ASCII table of the valid characters in a message:

 

     "A"  65   "a"  97   " "  32
     "B"  66   "b"  98   "!"  33
      .         .        ","  44
      .         .        "."  46
      .         .        ":"  58
     "Y"  89   "y"  121  ";"  59
     "Z"  90   "z"  122  "?"  63

The algorithm that you should use to encode messages is to take the ASCII value of each character in the message, starting with the last character in the message and ending with the first character in the message. You should then add on to the coded message this ASCII value written in reverse order. For example, if the ASCII value is 123, the encoded message should contain the string "321". There should be no spaces separating the numbers in the encoded message.

Input and Output

The input file consists of one or more lines with a normal (not encoded) or encoded message each.

 

Output file must have the same number of lines with the corresponding encoded message or the decoded one, respectively.

Sample Input

 

abc
798999
Have a Nice Day !

Sample Output

 

998979
cba
332312179862310199501872379231018117927
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char a[100];
    int i,j,n,l;
    while(gets(a))
    {
        int len=strlen(a);
        for(i=len-1;i>=0;)
        {
            if(!isdigit(a[i]))
            {
                n=a[i];
                while(n)
                {
                    printf("%d",n%10);
                    n/=10;
                }
                i--;
            }
            else
            {
                if(a[i]=='1')
                {
                    l=(a[i]-'0')*100+(a[i-1]-'0')*10+a[i-2]-'0';
                    i-=3;
                    printf("%c",l);
                }
                else
                {
                    l=10*(a[i]-'0')+a[i-1]-'0';
                    i-=2;
                    printf("%c",l);
                }
            }
        }
        printf("/n");
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值