题解:SP9637 BANDW - Black and White
遍历遍历 \(S\) 和 \(T\),如果 \(S_i\ne T_i\),就将答案加 \(1\),把 \(i\) 跳到下一个使 \(S_i=T_i\) 的地方。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
string S, T;
while (true) {
cin >> S >> T;
if (S == "*" && T == "*") {
break;
}
int moves = 0;
int n = S.length();
for (int i = 0; i < n; ++i) {
if (S[i] != T[i]) {
moves++;
while (i < n && S[i] != T[i]) {
i++;
}
i--;
}
}
cout << moves << endl;
}
return 0;
}

浙公网安备 33010602011771号