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); }
public void Expand() { bool b = false; while (!BinaryStdIn.IsEmpty()) { char cnt = BinaryStdIn.ReadChar(); for (int i = 0; i < cnt; i++) { BinaryStdOut.Write(b); } b = !b; } }
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(); }