public void Compress()
        {
            char cnt = (char)0;
            bool b, old = false;

            while (!BinaryStdIn.IsEmpty())
            {
                b = BinaryStdIn.ReadBoolean();
                if (b != old)
                {
                    BinaryStdOut.Write(cnt);
                    cnt = (char)0;
                    old = !old;
                }
                else
                {
                    if (cnt == 255)
                    {
                        BinaryStdOut.Write(cnt);
                        cnt = (char)0;
                        BinaryStdOut.Write(cnt);
                    }
                }
                cnt++;
            }
            BinaryStdOut.Write(cnt);
        }
 private static Node ReadTrie()
 {
     if (BinaryStdIn.ReadBoolean())
     {
         return(new Node(BinaryStdIn.ReadChar(), 0, null, null));
     }
     return(new Node('\0', 0, ReadTrie(), ReadTrie()));
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //LSDSort();
            //MSDSort();
            //Q3String();
            //StringSearch();
            //Regax();

            for (; !BinaryStdIn.IsEmpty();)
            {
                if (BinaryStdIn.ReadBoolean())
                {
                    StdOut.Print("1");
                }
                else
                {
                    StdOut.Print("0");
                }
            }
            StdOut.Println();
        }
        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);
            }
        }