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, whereNdenotes the length of data andDis 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 charactercin the sequence to transmit the encoded data. Each encoded charactercmust be lowercase English alphabets, i.e., alphabetsa-z.
Proceduredecode(M)that decodes the data, whereMdenotes 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_datafor at most M times. To output the decoded data, it must call procedureoutput_data(y)for each integeryin 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.,
encodemay not callsend_datamore than 100N times.
Subtask 2
- N <= 100.
- The encoded data should not contain more than 100N characters, i.e.,
encodemay not callsend_datamore than 100N times.
Subtask 3 (40 points)
- N <= 100.
- The encoded message should not contain more than 2N characters, i.e.,
encodemay not callsend_datamore than 2N times.


No comments :
Post a Comment