UVA之10878 - Decode the tape

简介:

【题目】

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.

Sample Input Sample Output
___________
| 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。
破译完毕。

【代码】

[cpp]  view plain copy
  1. /********************************* 
  2. *   日期:2013-5-3 
  3. *   作者:SJF0115 
  4. *   题号: 10878 - Decode the tape 
  5. *   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1819 
  6. *   结果:AC 
  7. *   来源:UVA 
  8. *   总结: 
  9. **********************************/  
  10. #include <stdio.h>  
  11. #include <string.h>  
  12.   
  13. int c[] = { 0, 0, 64, 32, 16, 8, 0, 4, 2, 1, 0};  
  14.   
  15. int main() {  
  16.     char str[15];  
  17.     int value,i;  
  18.     //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);     
  19.     gets(str);  
  20.     while(gets(str) && str[0] != '_'){  
  21.         value = 0;  
  22.         int len = strlen(str);  
  23.         for(i = 2;i < len;i++){  
  24.             if(str[i] == 'o'){  
  25.                 value += c[i];  
  26.             }  
  27.         }  
  28.         printf("%c",value);  
  29.     }  
  30. }  
目录
相关文章
UVa343 What Base Is This
UVa343 What Base Is This
43 0
|
人工智能 BI
UVa1554 - Binary Search
UVa1554 - Binary Search
45 0
LeetCode 91. Decode Ways
字母A到Z分别和1到26的数字一一对应,给定一串用字符表示的数字,将数字串从不同位置拆开,每一个数字都对应一个字符,如此构成了一个字母字符串. 从不同的位置拆分数字字符串,可以得到不同的字母字符串,问一共有多少种有效的拆分方式.
62 0
LeetCode 91. Decode Ways
|
存储 算法 测试技术
UVA240 Variable Radix Huffman Encoding
UVA240 Variable Radix Huffman Encoding
UVA240 Variable Radix Huffman Encoding
LeetCode 91 Decode Ways(编码方式)(*)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/51340198 ...
963 0
LeetCode 92 Decode Ways
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/51339103 ...
679 0
|
编解码 Sentinel Linux
[LeetCode] Encode and Decode Strings
Problem Description: Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.
892 0