欢迎访问我的新博客:http://www.milkcu.com/blog/

原文地址:http://www.milkcu.com/blog/archives/uva458.html

题目描述

 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.

解题思路

首先,编写一个小程序,获得解吗规则。

#include <stdio.h>
int main(void) {
char s1[] = "1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5";
char s2[] = "*CDC is the trademark of the Control Data Corporation.";
int i = 0;
while(s1[i] != '\0') {
printf("%4d%4d\n", s1[i], s2[i]);
i++;
}
return 0;
}

解码规则是ASCII码值减7。

代码实现

#include <stdio.h>
int main(void) {
int c;
while((c = getchar()) != EOF) {
if(c == '\n') {
putchar('\n');
} else {
putchar(c - 7);
}
}
return 0;
}

(全文完)

The Decoder - UVa458的更多相关文章

  1. C# 字符编码解码 Encoder 和Decoder

    在网络传输和文件操作中,如果数据量很大,需要将其划分为较小的快,此时可能出现一个数据块的末尾是一个不匹配的高代理项,而与其匹配的低代理项在下一个数据块. 这时候使用Encoding的GetBytes方 ...

  2. android openmax hardware decoder 整合记录

    欢迎访问我的blog:http://blog.thinkinside.me 关于android中openmax中hardware decoder的调用中,整合过程比较简单.主要是对OMXCodec的封 ...

  3. Verilog (二) multiplexer and decoder

    1  mutiplexer 数据选择器 1)  one-bit wide 2-1 mux wire dout = sel? din1 : din0; // conditional continuous ...

  4. 自定义Encoder/Decoder进行对象传递

    转载:http://blog.csdn.net/top_code/article/details/50901623 在上一篇文章中,我们使用Netty4本身自带的ObjectDecoder,Objec ...

  5. Netty4 自定义Decoder,Encoder进行对象传递

    首先我们必须知道Tcp粘包和拆包的,TCP是个“流”协议,所谓流,就是没有界限的一串数据,TCP底层并不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际数据进行包的划分,一个完整的包可能会被拆分 ...

  6. Deep Learning 学习随记(六)Linear Decoder 线性解码

    线性解码器(Linear Decoder) 前面第一章提到稀疏自编码器(http://www.cnblogs.com/bzjia-blog/p/SparseAutoencoder.html)的三层网络 ...

  7. python PIL except: IOError: decoder jpeg not available

    今天在Python运行环境的服务器弄一个有关图像处理的程序时报这样的错: 1 NameError: global name 'Image' is not defined import Image 了下 ...

  8. A neural chatbot using sequence to sequence model with attentional decoder. This is a fully functional chatbot.

    原项目链接:https://github.com/chiphuyen/stanford-tensorflow-tutorials/tree/master/assignments/chatbot 一个使 ...

  9. ubuntu14.04 安装PIL库出现OError: decoder jpeg not available 的解决方案

    出现 OError: decoder jpeg not available 的原因是,没有装JPEG的库,同时要支持png图片的话还要装 ZLIB.FREETYPE2.LITTLECMS的库文件. 先 ...

随机推荐

  1. MySQL JDBC的queryTimeout坑

    遇到一个MySQL JDBC跑execute规定的方法queryTimeout坑,更恶心,无论是BUG,不能,^_^,为什么要说?请看下面的说明: 现象: 用同一个Connection运行大批量SQL ...

  2. 配置路线图RouteMap注意事项

    路线图RouteMap一个特征是First Match Win.假设没有人RouteMap实例都满足,那么.默认拒绝操作,然后配置路线图时,有一点需要特别注意.否则容易出错,这是默认的处理.通常的做法 ...

  3. ExtJs在disabled和readOnly美学分析

    ExtJs中disabled和readOnly美观度的分析 ExtJs中.假设设置输入框为仅仅读属性,一般第一考虑的都是readonly=true 它的效果和正常输入框一样,可是不同意输入: 然而,它 ...

  4. Android复制WIN8点击下沉倾斜系统瓷砖效果

    ※效果 ※使用说明 Java代码 import android.app.Activity; import android.os.Bundle; import android.widget.Toast; ...

  5. 十天学Linux内核之第三天---内存管理方式

    原文:十天学Linux内核之第三天---内存管理方式 昨天分析的进程的代码让自己还在头昏目眩,脑子中这几天都是关于Linux内核的,对于自己出现的一些问题我会继续改正,希望和大家好好分享,共同进步.今 ...

  6. 使用sqlnet.ora限制IP访问

    他在最后一个超级遭遇了许多方法值,然后找到一个方法,在DB上限IP访问. http://blog.csdn.net/jacson_bai/article/details/18097805 ENV:   ...

  7. Android启动第三方应用程序

    主要是开始通过包名的第三方应用程序,获取的方法的包名是非常在线.不是说. 两种方式启动: 第一: Intent intent = new Intent(); intent.setClassName(& ...

  8. 刚刚回归的开始菜单 Windows 10全面体验

    北京时间2014年10月1日凌晨,微软就在旧金山召开新品公布会,对外展示了自己新一代操作系统Windows 10,覆盖了包含手机.平板.台式机以及Xbox One在内的全部平台.尽管微软此次公布的不过 ...

  9. Javascript闭包的一些研究

    原文:Javascript闭包的一些研究 本文不谈闭包的概念,因为概念容易把人搞晕,本文希望通过几个鲜活的例子来探究闭包的性质,相信对理解闭包会有所帮助. 程序1 var f = (function( ...

  10. [ Swift框架 ] # SwiftyJSON

    Swift写的关于转化JSON数据 https://github.com/SwiftyJSON/SwiftyJSON