You would like to transmit integer data through a special channel,
i.e., this channel only supports transmission of alphabets
The overall process is shown in the following figure.
a
- z
.
In order to do so, you have to encode the data into a sequence of
alphabets, transmit the encoded data, and decode it to obtain the
original integer data.The overall process is shown in the following figure.
You have to implement:
-
Procedure
encode(N,D)
that encodes the data, whereN
denotes the length of data andD
is an array of integers representing the data, whereD[i]
is the i-th integer in the data. (0 <=D[i]
<= 255.) This procedure must call proceduresend_data(c)
for each characterc
in the sequence to transmit the encoded data. Each encoded characterc
must be lowercase English alphabets, i.e., alphabetsa
-z
.
Proceduredecode(M)
that decodes the data, whereM
denotes the length of the encoded data. To read the encoded data as a sequence of characters, this procedure must call procedureread_data()
for each character in the sequence. It may callread_data
for at most M times. To output the decoded data, it must call procedureoutput_data(y)
for each integery
in the decoded data.
Follow Up
Subtask 1
- N <= 100 and 0 <=
D[i]
<= 25. - The encoded data should not contain more than 100N characters, i.e.,
encode
may not callsend_data
more than 100N times.
Subtask 2
- N <= 100.
- The encoded data should not contain more than 100N characters, i.e.,
encode
may not callsend_data
more than 100N times.
Subtask 3 (40 points)
- N <= 100.
- The encoded message should not contain more than 2N characters, i.e.,
encode
may not callsend_data
more than 2N times.
No comments :
Post a Comment