uva 10878 Decode the tape(字符密码推断)
来源:互联网 发布:信捷plc流程梯图编程 编辑:程序博客网 时间:2024/05/01 10:28
题目言简意赅,转一大神的题解:
输入从上往下看,可以看成题目所说的一段磁带。
题目给的信息很少,因此大部分信息要从输入输出得到。
(相当于给你一段明文跟密码,然后你破解其中的加密规则)
首先我们发现,磁带一共有43行,跟密码的字符个数一样(换行包括在内)。
可以猜测是否磁带的一行,代表一个字符。
然后我们可以发现,密码中相同的字符,在磁带里面的对应行,也是相同的。
更加坚定我们的猜测。
然后我们观察磁带里每行的结构。
其整体的格式一样,只有 “o” 的位置和数量有不同。
而且 “o” 只会在固定的7个位置出现。
则 7 个位置,一共可以表示出 2^7=128 种字符。
联系字符的整型特征(ASCII码),
可以猜测,磁带的每行表示着一个二进制数,这个二进制数的数值正好是对应字符的ASCII码。
看一下空格(ASCII码为32)的对应行 “ o . ”,
把行中的空格看作0,“o” 看作1,则可以得到二进制数0100000,正好是32。
破译完毕。
代码:
#include <stdio.h>int c[] = {0, 0, 64, 32, 16, 8, 0, 4, 2, 1, 0};int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL char str[15]; int ans, i; gets(str); while (gets(str) && str[0] != '_') { ans = 0; for (int i = 2; str[i] != '\0'; i++) { if (str[i] == 'o') { ans += c[i]; } } printf("%c", ans); } return 0;}
0 0
- 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
- ASP.NET MVC 过滤器(五)
- 作为一个程序员的投资
- Linux中profile、bashrc、bash_profile之间的区别和联系
- linux常用命令
- Eclipse下建立geoserver源码工程
- uva 10878 Decode the tape(字符密码推断)
- 标准为王
- nefu 118——n!后面有多少个0
- nginx 设置本地浏览器缓存文件,nginx gzip压缩
- 总结wordpress3.9版本运行缓慢的几种解决方案
- UVa 846 - Steps
- CentOS 6.5安装NodeJS
- 学习Linux的菜鸟(DNS服务器的安装与配置)
- lua学习笔记04