Пример #1
0
        public void Expand()
        {
            string[] st = new string[L];
            int      i; // 下一个待补全的编码值

            for (i = 0; i < R; i++)
            {
                st[i] = "" + i;
            }
            st[i++] = " ";//EOF
            int    codeword = BinaryStdIn.ReadInt(W);
            string val      = st[codeword];

            while (true)
            {
                BinaryStdOut.Write(val); //输出当前字符串
                codeword = BinaryStdIn.ReadInt(W);
                if (codeword == R)
                {
                    break;
                }
                string s = st[codeword]; //获取下一个编码
                if (i == codeword)
                {
                    s = val + val[0]; //根据上一个字符串首字母得到编码的字符串
                }
                if (i < L)
                {
                    st[i++] = val + s[0]; //为编译表添加新的条目
                }
                val = s;
            }
        }
        public void Expand()
        {
            Alphabet DNA = new Alphabet("ACTG");
            int      w   = DNA.LgR();
            int      n   = BinaryStdIn.ReadInt();

            for (int i = 0; i < n; i++)
            {
                var c = BinaryStdIn.ReadChar(w);
                BinaryStdOut.Write(DNA.ToChar(c));
            }
        }
        public void Expand()
        {
            Node root = ReadTrie();
            int  n    = BinaryStdIn.ReadInt();

            for (int i = 0; i < n; i++)
            {
                var x = root;
                while (!x.isLeaf())
                {
                    if (BinaryStdIn.ReadBoolean())
                    {
                        x = x.Right;
                    }
                    else
                    {
                        x = x.Left;
                    }
                }
                BinaryStdOut.Write(x.Ch);
            }
        }