暴力枚举
不知道为什么,在蓝桥杯那里能过去,但是在y总这里只能过11个数据
还有需要注意每组数据的输入和输出是反过来的,输入在第二行,输出在第一行,我说怎么看案例有点不符合题意的嘞,原来是自己没看清题。
import java.io.*;
public class Main {
static int N = 100000 + 10;
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
while (n-- > 0) {
char[] end = br.readLine().toCharArray();
char[] start = br.readLine().toCharArray();
int res = 0;
// 特判一下 开始和结尾 是不是相等
if (start[0] != end[0] || start[start.length - 1] != end[end.length - 1]) {
res = -1;
} else {
for (int i = 1; i < start.length - 1; i++) {
// 不相等,则翻转这个位置
if (start[i] != end[i]) {
// 判断是否符合翻转条件
if (start[i - 1] == start[i + 1]
&& start[i - 1] == start[i + 1]
&& start[i - 1] != start[i]
&& start[i] != start[i + 1]) {
res++;
} else {
res = -1;
break;
}
}
}
}
System.out.println(res);
}
}
}