zoukankan      html  css  js  c++  java
  • [Intermediate Algorithm]

    题目

    传入二进制字符串,翻译成英语句子并返回。

    二进制字符串是以空格分隔的。

    提示

    String.charCodeAt()
    String.fromCharCode()

    测试用例

    • binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111") 应该返回 "Aren't bonfires fun!?"
    • binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001") 应该返回 "I love FreeCodeCamp!"

    分析思路

    1. 将二进制字符串转换成十进制;
    2. 将十进制转换成对应的字符;
    3. 将字符连接成字符串;

    代码

    function binaryAgent(str) {
      
      return str.split(" ").map(function(val) {
        return String.fromCharCode(parseInt(val, 2));
      }).join("");
    }
    
    binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
    
  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/water-moon/p/6904643.html
Copyright © 2011-2022 走看看