1496 MTF正变换


Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 32M

Problem types
Allowed languages
C, C++, Java, Python

Description

MTF正变换的具体做法是维持一张表,开始时表中的Value均和Index相等,遇到输入时就在表中找到和输入值相等的表项,输出该项的Index的同时将该项移动到最前端,如下表所示:

输入 3 1 4 1 5 9 2 6 …

Value 0 1 2 3 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入3,3对应的Index被输出,同时3被移动到前端

Value 3 0 1 2 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入1,1对应的Index被输出,同时1被移动到前端

Value 1 3 0 2 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入4,4对应的Index被输出,同时4被移动到前端

……

输出 3 2 4 1 5 …

Input

输入约有20000行整数,范围在[0,65535]

Output

依次输出变换的结果,一行一个

Sample

Input

3
1
4
1
5

Output

3
2
4
1
5

Source: 仙剑魔


Comments

There are no comments at the moment.