zoukankan      html  css  js  c++  java
  • 字符串系列——磁带破解 Decode the tape

    Decode the tape
    Time Limit: 1 second

    "Machines take me by surprise with great frequency."
    Alan Turing

    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.
    

    很水的题,判断读入8个二进制转换后用ASCII码输出就解决了。

    代码如下:

    #include<stdio.h>
    #include<ctype.h>
    
    int main()
    {
        int i = 0, num;
        int n[10] = {0}, tmp;
    
        for (; (tmp = getchar()) != EOF;)
        {
            if (tmp == ' ')
            {
                n[i] = 0;
                i ++;
            }
            if (tmp == 'o')
            {
                n[i] = 1;
                i ++;
            }
            //printf("i = %d, n[%d] = %d\n", i, i - 1, n[i - 1]);
            if (i == 8)
            {
                i = 0;
                num = n[0]*128+n[1]*64+n[2]*32+n[3]*16+n[4]*8+n[5]*4+n[6]*2+n[7]*1;
                printf("%c", num);
            }
        }
        return 0;
    }
    


  • 相关阅读:
    tp5 select回显
    toFixed
    用js来实现银行家算法
    js 日期证有效性验的通用方法
    js获取或判断任意数据类类型的通用方法(getDataType)和将NodeList转为数组(NodeListToArray)
    js实现jquery函数animate动画效果
    js原生实现 无缝滚动图片
    scrollTop实现图像循环滚动(实例1)
    commonCookie.js
    delphi XE3解析JSON数据
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212194.html
Copyright © 2011-2022 走看看