cswork / OA打开练习工作台

IxlOA #3

Anagram Difference

估计简单可在线判题

考点(AI 标注)哈希计数字符串

For each pair of lowercase strings, find the minimum number of characters to replace on either side to make them anagrams; return −1 if their lengths differ.

输入格式

The first line contains q (1≤q≤100); each test case gives two strings: first |a| and |b|, then each string on its own line. An empty string is written as a line containing only -; non-empty strings contain only a-z, with length≤10000.

输出格式

For each test case, output one line with the minimum number of replacements; output −1 if the lengths differ.

样例 1

输入:

3
3 3
tea
ate
3 3
tea
toe
3 4
act
acts

输出:

0
1
-1

样例说明

Derive a linear-scan/dynamic-programming solution directly from the problem rules; the examples have been checked case by case against an independently built oracle.