题解: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;
}

posted @ 2024-10-19 08:53  cly312  阅读(9)  评论(0)    收藏  举报