问题2870--Prefix Sort

2870: Prefix Sort

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

Give you a permutation of 8 numbers(every number is between 1 and 8, and all the numbers are distinct); You are asked to find minimum steps to change the sequence to the ascending order by only allowed to reversed first k(1 <= k <= 8) numbers(cost one step);

输入

One string as describe above(no space between the numbers).

输出

Output the minimum steps to get the ascending order.

样例输入 Copy

12345678
56781234

样例输出 Copy

0
3

提示

For the second sample: 56781234 -> 87651234 (the first step) -> 43215678 (the second step) -> 12345678 (the third step)

来源/分类