283 - Compress

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 283 Compress - Why?

I think there may be other characters besides `A'..`Z', `a'..`z', space, `.', `,' , `-' and `\$' in the input. I rewrote my code to handle any character and got AC.
Check input and AC output for thousands of problems on uDebug!

metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 283 - Compress

The problem statement is not so clear, after try some time, I got AC.
As mentioned before, you can use all bit length code, but every time you used a code, the "prefix" is get longer, for example, the sample input:

Code: Select all

2
3
Hello Contestant,\$
Please write a program which gives\$
the text Hello world.\$
1
To be or not to be, that is the question.\$
The output and corresponding coding scheme as below:

Code: Select all

335
= 9 0000
e = 9 0001
t = 7 0010
l = 6 0011
o = 5 0100
a = 4 0101
r = 4 0110
\$ = 3 0111
h = 3 1000
i = 3 1001
s = 3 1010
w = 3 1011
H = 2 1100
g = 2 1101
n = 2 1110
, = 1 1111000
. = 1 1111001
C = 1 1111010
P = 1 1111011
c = 1 1111100
d = 1 1111101
m = 1 1111110
p = 1 11111110
v = 1 111111110
x = 1 111111111
167
= 9 000
t = 6 001
o = 5 010
e = 4 011
b = 2 100
h = 2 101
i = 2 110
n = 2 111000
s = 2 111001
\$ = 1 111010
, = 1 111011
. = 1 111100
T = 1 111101
a = 1 111110
q = 1 1111110
r = 1 11111110
u = 1 11111111