Canadian Computing Competition: 2006 Stage 2, Day 1, Problem 3
Note: The problem has been modified from the original so that it can work under the DM::OJ system. For the original problem statement, click here.
The problem of lossless data compression is to transform some data into a compressed form such that:
- The original can be reproduced exactly from the compressed form
- The compressed form is as small as can reasonably be achieved
You are to write a program that first encodes a line of input into a string of bits, and then is able to decode that string of bits back into the original line of input. Your program will be graded on both its correctness and the length of the encoded string it outputs. Additionally, your program will be run twice, first with the original input (you are expected to output the encoded string) and then with the encoded string you outputted from the first run (you are expected to output the original input text.
Scoring is as follows:
- If you do not output the original text on the second run of your program, you score
points - If the encoded string consists of anything other than the characters
1
and0
, you score points - If the encoded string has a length strictly greater than
times that of the original input text, you score points - Otherwise, you score
out of a possible points (where is the length of the original input text and is the length of your encoded string).
Constraints
Input Specification
The first line contains a single integer
If
If 0
and 1
, terminated by a newline character (ASCII value
Output Specification
If 0
and 1
, terminated by a newline character (ASCII value
If
Note that your output when
Sample Input 1 (First Run)
1
Hello, World!
Goodbye, World!
Sample Output 1 (First Run)
010101010
Sample Input 2 (Second Run)
2
010101010
Sample Output 2 (Second Run)
Hello, World!
Goodbye, World!
Comments
For anyone that isn't sure about what to do, the original problem statement has some hints and discussion on the problem.