UVA 10878 - Decode the tape
来源:互联网 发布:js获取标签所有属性 编辑:程序博客网 时间:2024/05/16 10:06
Your boss has just unearthed a roll of old computer tapes. The tapes have holes in them and might contain some sort of useful information. It falls to you to figure out what is written on them.
Input
The input will contain one tape.
Output
Output the message that is written on the tape.
___________| o . o|| o . || ooo . o|| ooo .o o|| oo o. o|| oo . oo|| oo o. oo|| o . || oo . o || ooo . o || oo o.ooo|| ooo .ooo|| oo o.oo || o . || oo .oo || oo o.ooo|| oooo. || o . || oo o. o || ooo .o o|| oo o.o o|| ooo . || ooo . oo|| o . || oo o.ooo|| ooo .oo || oo .o o|| ooo . o || o . || ooo .o || oo o. || oo .o o|| o . || oo o.o || oo . o|| oooo. o || oooo. o|| o . || oo .o || oo o.ooo|| oo .ooo|| o o.oo || o. o |___________
A quick brown fox jumps over the lazy dog.
Problemsetter: Igor Naverniouk
Special thanks: BSD games ppt.
【解析】:
输入从上往下看,可以看成题目所说的一段磁带。
题目给的信息很少,因此大部分信息要从输入输出得到。
(相当于给你一段明文跟密码,然后你破解其中的加密规则)
首先我们发现,磁带一共有43行,跟密码的字符个数一样(换行包括在内)。
可以猜测是否磁带的一行,代表一个字符。
然后我们可以发现,密码中相同的字符,在磁带里面的对应行,也是相同的。
更加坚定我们的猜测。
然后我们观察磁带里每行的结构。
其整体的格式一样,只有 “o” 的位置和数量有不同。
而且 “o” 只会在固定的7个位置出现。
则 7 个位置,一共可以表示出 2^7=128 种字符。
联系字符的整型特征(ASCII码),
可以猜测,磁带的每行表示着一个二进制数,这个二进制数的数值正好是对应字符的ASCII码。
看一下空格(ASCII码为32)的对应行 “ o . ”,
把行中的空格看作0,“o” 看作1,则可以得到二进制数0100000,正好是32。
破译完毕。
【代码】:
/********************************** 日期:2013-5-3* 作者:SJF0115* 题号: 10878 - Decode the tape* 来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1819* 结果:AC* 来源:UVA* 总结:**********************************/#include <stdio.h>#include <string.h>int c[] = { 0, 0, 64, 32, 16, 8, 0, 4, 2, 1, 0};int main() {char str[15];int value,i;//freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin); gets(str);while(gets(str) && str[0] != '_'){value = 0;int len = strlen(str);for(i = 2;i < len;i++){if(str[i] == 'o'){value += c[i];}}printf("%c",value);}}
- UVa 10878 - Decode the tape
- uva 10878 Decode the tape
- uva-10878 - Decode the tape
- uva 10878 - Decode the tape
- UVa 10878 - Decode the tape
- Uva - 10878 - Decode the tape
- UVA 10878 - Decode the tape
- UVa 10878 - Decode the tape
- UVA 10878 - Decode the tape
- UVA 10878 Decode the tape
- UVa - 10878 - Decode the tape
- UVA 10878 Decode the tape
- uva 10878 Decode the tape
- UVa 10878 - Decode the tape
- uva 10878 decode the tape
- uva - 10878 - Decode the tape
- uva 10878 Decode the tape
- UVA 10878 Decode the tape
- Linux网络编程入门(经典)
- 标准的Makefile目标
- JAVA学习笔记(二)金字塔、求和、数组定义、冒泡排序
- 十六进制字符串与十进制的转换函数 II
- Javascript 风格向导(终结)
- UVA 10878 - Decode the tape
- Ubuntu下用apache+perl搭建最简单的聊天室
- 观察者模式(Observer Pattern)(二):HeadFirst中的气象站的实现
- 黑马程序员_I/O流(字符编码问题)
- 客户端Javascript学习笔记-----脚本化文档
- 进程与线程的一个简单解释
- 在办公室谈论工资话题的技巧
- 观察者模式(Observer Pattern)(三):使用java内置的支持实现HeadFirst气象站
- JAVA的MAP的方法