首页 > 其他 > 详细

UVa OJ 458

时间:2014-01-29 14:09:55      阅读:382      评论:0      收藏:0      [点我收藏+]

 

 The Decoder 

Write a complete program that will correctly decode a set of characters into a valid message. Your program should read 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 a single 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 same encoding scheme and should print the actual message of each set of characters.

 

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.

 

bubuko.com,布布扣
 1 #include <stdio.h>
 2 #include <string.h>
 3 #define maxn 10000
 4 int main()
 5 {
 6 #ifdef CLOCK
 7     freopen("data.in", "r", stdin);
 8     freopen("data.out", "w", stdout);
 9 #endif
10     int i;
11 #ifdef LOCAL
12     FILE * fin,* fout;
13     fin = fopen("data.in", "rb");
14     fout = fopen("data.out", "wb");
15 #endif
16     char buf[maxn];
17     memset(buf, 0, sizeof(buf));
18     while (fgets(buf, sizeof(buf), stdin))
19     {
20         for (i = 0; i < strlen(buf); i++)
21             buf[i] -= 7;
22         buf[i - 1] = \0;
23         printf("%s\n", buf);
24     }
25 #ifdef LOCAL
26     fclose(fin);
27     fclose(fout);
28 #endif
29     return 0;
30 }
bubuko.com,布布扣

 

报告:还是比较顺的解决了,只是其中因为\r\n的问题纠结一下,strlen的长度实际是指到‘\0‘,且包括\n,即题中buf[i]为‘\0‘,buf[i-1]为‘\n‘。而当用到fprintf时,printf("%s\n", buf);改为fprintf("%s\r\n", buf);即后面需要加上\r\n来实现换行。

 

问题:无

 

解决:无

 

UVa OJ 458

原文:http://www.cnblogs.com/X-Spider/p/3535964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!