question: public static void compress ( ) { String s = BinaryStdIn . readString ( ) ; char [ ] input = s . toCharArray ( ) ; int [ ] freq = new int [ R ] ; for ( int i = 0 ; i < input . length ; i ++ ) freq [ input [ i ] ] ++ ; Node root = buildTrie ( freq ) ; String [ ] st = new String [ R ] ; buildCode ( st , root , "" ) ; writeTrie ( root ) ; BinaryStdOut . write ( input . length ) ; for ( int i = 0 ; i < input . length ; i ++ ) { String code = st [ input [ i ] ] ; for ( int j = 0 ; j < code . length ( ) ; j ++ ) { if ( code . charAt ( j ) == '0' ) { BinaryStdOut . write ( false ) ; } else if ( code . charAt ( j ) == '1' ) { BinaryStdOut . write ( true ) ; } else throw new IllegalStateException ( "Illegal state" ) ; } } BinaryStdOut . close ( ) ; }
target:  Reads a sequence of 8-bit bytes from standard input; compresses them using TTT codes with an 8-bit alphabet; and writes the results to standard output.