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>
#include <string.h>
#define maxn 10000
int main()
{
#ifdef CLOCK
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
int i;
#ifdef LOCAL
FILE * fin,* fout;
fin = fopen("data.in", "rb");
fout = fopen("data.out", "wb");
#endif
char buf[maxn];
memset(buf, , sizeof(buf));
while (fgets(buf, sizeof(buf), stdin))
{
for (i = ; i < strlen(buf); i++)
buf[i] -= ;
buf[i - 1] = '\0';
printf("%s\n", buf);
}
#ifdef LOCAL
fclose(fin);
fclose(fout);
#endif
return ;
}

报告:还是比较顺的解决了,只是其中因为\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的更多相关文章

  1. uva oj 567 - Risk(Floyd算法)

    /* 一张有20个顶点的图上. 依次输入每个点与哪些点直接相连. 并且多次询问两点间,最短需要经过几条路才能从一点到达另一点. bfs 水过 */ #include<iostream> # ...

  2. UVa OJ 194 - Triangle (三角形)

    Time limit: 30.000 seconds限时30.000秒 Problem问题 A triangle is a basic shape of planar geometry. It con ...

  3. UVa OJ 175 - Keywords (关键字)

    Time limit: 3.000 seconds限时3.000秒 Problem问题 Many researchers are faced with an ever increasing numbe ...

  4. UVa OJ 197 - Cube (立方体)

    Time limit: 30.000 seconds限时30.000秒 Problem问题 There was once a 3 by 3 by 3 cube built of 27 smaller ...

  5. UVa OJ 180 - Eeny Meeny

    Time limit: 3.000 seconds限时3.000秒 Problem问题 In darkest <name of continent/island deleted to preve ...

  6. UVa OJ 140 - Bandwidth (带宽)

    Time limit: 3.000 seconds限时3.000秒 Problem问题 Given a graph (V,E) where V is a set of nodes and E is a ...

  7. 548 - Tree (UVa OJ)

    Tree You are to determine the value of the leaf node in a given binary tree that is the terminal nod ...

  8. UVa OJ 10300

    Problem A Ecological Premium Input: standard input Output: standard output Time Limit: 1 second Memo ...

  9. UVa OJ 10071

    Problem B Back to High School Physics Input: standard input Output: standard output A particle has i ...

随机推荐

  1. js 中call,apply,bind的区别

    call.apply.bind方法的共同点与区别: apply.call.bind 三者都是用来改变函数的this对象的指向: apply.call.bind 三者都可以利用后续参数传参: bind ...

  2. 1Q84 BOOK 1-3 笔记

    1Q84 BOOK 1-3 村上春树 18个笔记     ◆ 第2章 青豆 不要被外表迷惑   >> 在这三十年的人生中,究竟听过多少次同样的台词?为了这个姓氏,曾经多少次遭人调侃?如果不 ...

  3. Java输入/输出(I/O)流的分类总结

    java.io中有四个重要的抽象类: InputStream(字节输入流) Reader(字符输入流) OutputStream(字节输出流) Writer(字符输出流) 其中,InputStream ...

  4. [Selenium] Selenium common Actions Examples

    1.sendKeys() 在文本框中输入字符串 WebElement searchBox = driver.findElement(By.name("q")); searchBox ...

  5. 安卓开发eclipse如何导出项目

    安卓开发如何导出项目 方法/步骤   1 首先打开eclipse 2 选择file然后选择export 3 选择android application 4 点击next 5 选择项目browse可以更 ...

  6. 【旧文章搬运】Windbg+Vmware驱动调试入门(四)---VirtualKD内核调试加速工具

    原文发表于百度空间,2009-01-09========================================================================== 今天又想起 ...

  7. caffe 入门实例3 fine-turning

    占坑,使用fine-turning初始化参数...

  8. linux中目录操作<1>

    一.目录的权限 (1)目录文件的访问权限分为三组,分别为所有者,用户,其他.每个权限组的权限位有3个,分别为读.写.执行. 注意:可以使用stat函数得到目录文件的状态信息.权限为在stat结构中st ...

  9. 任务17:从UML角度来理解依赖

    什么是依赖 如果我们用EF操作数据库. 那么CustomerController就对Context形成了依赖. 我们这种依赖的写法就是隐式的依赖 显式依赖于隐式依赖 怎么理解隐式的依赖呢? 三层架构是 ...

  10. Cardboard profile的修改

    Cardboard盒子中,手机屏幕大小.镜片离屏幕距离,屏幕分辨率等都会影响配戴者的眼中成像,通过对生成图像的变形可以部份解决这一问题,cardboard sdk中提供了cardboardprofil ...