[解题报告]The Decoder

题目大意

题目原文:http://uva.onlinejudge.org/external/4/458.pdf

背景

编一个程序,将一串字符进行解码,解码之后打印出这串字符

 

Sample Input

 1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5

 

Sample Output

*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.

算法:

问题的关键就是在找出解码之后与解码之前的关系,也就是我代码中的t='1'-'t';

这就是问题的所在,之后其他的代码解码也就是按照这样的关系进行下去了。

代码:这里附上我的代码,你可以去这里提交你的代码验证你的代码是否正确,

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int t,i;
 6     char s[1000];
 7 
 8     t='1'-'*';
 9 
10     while(gets(s)!=NULL)
11     {
12         int num=strlen(s);
13         for(i=0;i<num;i++)
14             s[i]-=t;
15         puts(s);
16     }
17     return 0;
18 }

 

posted @ 2013-02-04 20:15  乱七八糟 。  阅读(211)  评论(0编辑  收藏  举报