模拟,从第一位开始,如果当前第一个字符串和第二个字符串同一位上的字符不相等,就相应的改变字符,并将计数器temp++,扫一遍字符串就行,时间复杂度是O(n)的
#include<bits/stdc++.h>
using namespace std;
string a,b;
int temp;
int main()
{
cin>>a>>b;
int len=a.length();
for(int i=0;i<=len-1;i++)
{
if(a[i]!=b[i])
{
a[i]=b[i];
temp++;
if(a[i+1]=='*') a[i+1]='o';
else a[i+1]='*';
}
}
cout<<temp<<endl;
}