美文网首页
如何加入LSGO软件技术团队?

如何加入LSGO软件技术团队?

作者: 老马的程序人生 | 来源:发表于2019-06-24 20:17 被阅读0次

    背景

    马上就要放暑假了! LSGO软件技术团队 也要开始招新了!

    本次招入的同学,我会亲自来带,和你一起学习,共同成长。

    我的CSDN博客

    我们的主要研究方向是机器学习,再详细一些就是视觉、自然语言处理和量化金融。

    以下是我对团队运营的一些启示:

    欢迎新同学加入进来,我的联系方式如下,直接与我联系就好!


    代码

    <b>Huffman 字典结构</b>:

    <u>C#语言</u>

    public class HuffmanDicItem
    {
        public char Character { get; set; }
        public string Code { get; set; }
        public HuffmanDicItem(char charactor, string code)
        {
            Character = charactor;
            Code = code;
        }
    }
    

    <b>Huffman 字典</b>:

    <u>C#语言</u>

    char[] character =
    {
        'l', 'r', ' ', '.', 'e', 'c', 's', 'p', 'u', 'g', 'o', 'M', 'y', 'W', 'h', 'a', 't', 'i',
        'n'
    };
    
    string[] code =
    {
        "0000", "0001", "001", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011",
        "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
    };
    
    List<HuffmanDicItem> dic = character.Select((t, i) => new HuffmanDicItem(t, code[i])).ToList();
    

    <u>Python语言</u>

    character = [
         'l', 'r', ' ', '.', 'e', 'c', 's', 'p', 'u', 'g', 'o', 'M', 'y', 'W', 'h', 'a', 't', 'i', 'n'
    ]
    
    code = [
        "0000", "0001", "001", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011",
        "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
    ]
    dic = dict(zip(character, code))
    

    <b>解码函数</b>:

    <u>C#语言</u>

    public string HuffmanCodeToString(List<HuffmanDicItem> dict, string code)
    {
        string result = string.Empty;
        for (int i = 0; i < code.Length;)
        {
            foreach (HuffmanDicItem item in dict)
            {
                if (code[i] == item.Code[0] && item.Code.Length + i <= code.Length)
                {
                    string temp = code.Substring(i, item.Code.Length);
                    if (temp == item.Code)
                    {
                        result += item.Character;
                        i += item.Code.Length;
                        break;
                    }
                }
            }
        }
        return result;
    }
    

    <u>Python语言</u>

    def HuffmanCodeToString(dict, code):
        result = ""
        i = 0
        while i < len(code):
            for item in dict:
                if code[i] == dict[item][0] and len(dict[item]) + i <= len(code):
                    temp = code[i:i + len(dict[item])]
                    if temp == dict[item]:
                        result += item
                        i += len(dict[item])
                        break
        return result
    

    <b>Huffman 编码</b>:

    <u>C#语言</u>

    string huffmanCode =
        "110001100100111010010101101101111100111010011111001110011111101100101100010010000011110101011101000011011100110000100";
    string res = HuffmancodeToString(dic, huffmanCode);
    Console.WriteLine(res);
    

    <u>Python语言</u>

    huffmanCode = "110001100100111010010101101101111100111010011111001110011111101100101100010010000011110101011101000011011100110000100"
    res = HuffmanCodeToString(dic, huffmanCode)
    print(res)
    

    总结

    欢迎同学们与我联系,希望我们能够结善缘!


    相关图文

    相关文章

      网友评论

          本文标题:如何加入LSGO软件技术团队?

          本文链接:https://www.haomeiwen.com/subject/rwlaqctx.html