1167. Weird Mapping between Words and Integers

单点时限: 2.0 sec

内存限制: 256 MB

Consider the following bijection between words from the alphabet {a,b} and the the set of non-negative integers, N:

f: {a,b}* -> N

e -> 0 (empty word)

a -> 1

b -> 2

aa -> 3

ba -> 4

ab -> 5

bb -> 6

aaa -> 7

baa -> 8

Your task is to write a program that can transform words from alphabet {a,b} with maximum size less than 30 into the corresponding integers and also transform integers into the corresponding words, according to the mapping defined above.

输入格式

The input consists of a sequence of lines and each line can either be a word from the alphabet or an integer. It is guaranteed that the given integer corresponds to a word of maximum size less than 30. All the words in the input are non-empty and the integers are greater than zero.

输出格式

For each line of input, a word or an integer, you should output also in separate lines the corresponding integer or word according to the mapping defined above.

样例

Input
b
5
aaa
18
Output
2
ab
7
bbaa

8 人解决,12 人已尝试。

8 份提交通过,共有 20 份提交。

6.4 EMB 奖励。

创建: 15 年,6 月前.

修改: 5 年,3 月前.

最后提交: 2 年前.

来源: partychen

题目标签