查看: 1263|亚博体育登录失败: 0
打印 上一主题 下一主题

Encode and Decode

online_moderator 发表于 2010-4-11 21:07:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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.


下一篇:Study Room
您需要登录后才可以回帖 登录 | 加入驿站 qq_login



站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号tongdun|网站地图wx_jqr

GMT+8, 2019-7-13 03:38

Powered by Discuz! X3.4

© 2009-2019

快速亚博体育登录失败 返回顶部 返回列表