仔细分析问题,发现其实就是一个递推的问题,按照顺序从左向右依次判断是否相等,不相等就改变两个状态
相等就继续往下遍历,当遍历完之后,是一定有解的,所以不用使用bfs,因为它只有一个最优解
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int n;
char start[N], aim[N];
void turn(int i)
{
if (start[i] == '*') start[i] = 'o';
else start[i] = '*';
}
int main()
{
cin >> start >> aim;
n = strlen(start);
int res = 0;
for (int i = 0; i < n - 1; i++) {
if (start[i] != aim[i]) {
turn(i);
turn(i + 1);
res++;
}
}
cout << res << endl;
return 0;
}