现在的位置: 首页 > 综合 > 正文

458 – The Decoder

2013年08月14日 ⁄ 综合 ⁄ 共 1520字 ⁄ 字号 评论关闭


 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{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

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

AC代码

#include <stdio.h>
#include <string.h>

#define MAXN 	100+10

int main(void)
{
#ifdef	TEST
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	char 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;
}

抱歉!评论已关闭.