458 - The Decoder
来源:互联网 发布:中班美工交通标志教案 编辑:程序博客网 时间:2024/06/06 02:11
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{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 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{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.
解题思路:
本题知道破译字符串的方法即可,通过样例中的输入输出,我们可以很快的发现破译前和破译后字符的ASCII码相差7。对于字符串的输入输出,scanf和printf的效率要高于cin和cout,且本题有多组输入输出,所以该题我用了C语言的输入输出和cstring头文件。
AC代码:
#include <iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char message[1000]; int length; while( scanf("%s", message) != EOF )//输入需要破译的字符串 { length=strlen( message );//求得字符串长度 for(int i = 0; i < length; i++) { message[i] -= 7;//每个字符ASCII码减7便能破译出原始字符 } printf("%s\n", message);//输出破译后的字符串 } return 0;}
0 0
- Uva 458 - The Decoder
- UVa 458 - The Decoder
- 458 - The Decoder
- 458 - The Decoder
- uva 458 The Decoder
- UVA 458 - The Decoder
- uva-458 - The Decoder
- 458 - The Decoder
- uva 458 The Decoder
- UVaOJ 458 - The Decoder
- 458 - The Decoder
- UVa 458 - The Decoder
- UVA 458 The Decoder
- 458 - The Decoder
- 458 - The Decoder
- 458 - The Decoder
- 458 - The Decoder
- UVA - 458 - The Decoder
- android中TexiView加下,中划线
- find命令详解
- Android app widget中实现跑马灯效果
- 深拷贝和浅拷贝的理解?
- 关于mysql删除唯一约束的问题(求解答)
- 458 - The Decoder
- java中String、StringBuffer和StringBuilder的区别
- hdu 4452 Running Rabbits
- APP测试流程~开启博客之旅
- 第一章 LINUX 常用命令
- poj 4044 Score Sequence(暴力)
- 微软面试100题2010年版全部答案集锦(含下载地址)
- opencv Error:Bad argument <Unknown arrray type> in cvarrTomat
- H.264与MPEG4区别