MicrosoftOA #47
Minimize Difference Between Two Numbers
估计中等可在线判题
The two strings have the same length and no leading zeros. One operation swaps the digits of the two strings at the same position. First, the absolute difference of the final values must be as small as possible; then, among those options, minimize the number of swaps.
This site uses a standard input/output protocol.
输入格式
Two lines S and T, of length 1..100000, with characters 0..9 and no leading zeros.
输出格式
Output a single integer, the answer.
样例 1
输入:
29162
10524
输出:
2
样例 2
输入:
123
123
输出:
0
样例 3
输入:
19
21
输出:
0
样例说明
Example 1: swapping positions 2 and 4 gives 20122 and 19564, with a difference of 558, using 2 swaps. Example 2: the strings are already identical, so no swap is needed. Example 3: the ones digit already offsets the tens difference, and the original difference 2 is minimal, so 0 swaps.