P8597 题解
sunkuangzheng · · 题解
【题目分析】
直接模拟即可。
如果当前位置的两串的字符不同,那么这个位置的硬币就必须要翻转。又因为题目说一定有解,所以不存在最后一个字符不同而倒数第二个字符相同的情况。所以我们只需逐位遍历,模拟统计即可。
【完整代码】
#include <bits/stdc++.h>
using namespace std;
char a[1005],b[1005];
int ans;
int main(){
cin >> a >> b;
int l = strlen(a);
for(int i = 0;i < l;i ++){
if(a[i] != b[i]){
ans ++;
a[i+1] = (a[i+1] == '*'?'o':'*');//下一个硬币也要翻转
}
}
cout << ans;
return 0;
}