458 - The Decoder

来源:互联网 发布:托福英语辅导机构知乎 编辑:程序博客网 时间:2024/05/19 06:39


 The Decoder 

Write a complete program that will correctly decode a set ofcharacters into a valid message. Your program shouldread a given file of a simple coded set of characters and print the exact message that the characters contain. The code key for this simple coding is a one for one character substitution based upon asingle arithmetic manipulation of the printable portion of the ASCII character set.

Input and Output

For example: with the input file that contains:

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

your program should print the message:

*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.

Your program should accept all sets of characters that use the sameencoding scheme and should print the actual message of each set ofcharacters.

Sample Input

1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu51PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu51KLJ'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.


AC代码

#include <stdio.h>#include <string.h>#define MAXN 100+10int main(void){#ifdefTESTfreopen("data.in", "r", stdin);freopen("data.out", "w", stdout);#endifchar str[MAXN];int i, n;while(scanf("%s", str) != EOF) {n = strlen(str);for (i=0; i<n; ++i) str[i] -= 7;printf("%s\n", str);}return 0;}


原创粉丝点击