IBMOA #36
Get Minimum Difference
Estimated EasyJudge-ready
For each pair of strings, you may replace any characters so that the two strings have the same character counts; find the minimum number of replacements. If the lengths differ, it is impossible; output -1.
Input
The first line contains n; each pair then takes two lines, and an empty string is given as an empty line. 1≤n≤100, lowercase letters; each string has length 0..10000, and each pair has total length 1..10000.
Output
Output n lines; line i is the minimum number for the i-th pair, or -1 if it is impossible.
Example 1
Input:
3
tea
ate
tea
toe
act
acts
Output:
0
1
-1
Example 2
Input:
1
a
Output:
-1
Example 3
Input:
1
aa
bb
Output:
2
Example notes
The examples output, line by line, 0, 1, -1; -1; and 2 respectively.
Editorial
Loading solution…