本帖最后由 haoran 于 2010-4-11 21:13 编辑 |
Mr. Encript is working on information transmission. One part of his job is to encode and decode an article. The encoding part is really simple:
1. Give a string of characters at first. This string should contain all the characters in the article. In this string, each character will appear only once. Each character has a code index. The character’s index is this character's position in the string, starts from position 0.
2. Assume character C is at the position 0 of the string, and then find out how many C in the article to be encoded, and record the positions C appear in the article. Output the number of character C, and then output the positions, separated by a blank space.
3. Process the next character (at the position 1) of the string as step 2. Repeat until process the whole string.
4. The new number sequence is the code wanted.
For example, given a index string:
String A B C D +
Position 0 1 2 3 4 5
and a article to be encoded:
Article C A B C A D
Position 0 1 2 3 4 5 6
The code we can get is:
2 1 5 1 2 2 0 4 1 6 1 3 0
A B C D +
Mr. Encript needs someone to finish the decoding part. So he gives the decoding job to you. You should write a program which can output the article with index string and the code sequence.