Source Code
#include <iostream>
#include <bits/stdc++.h>

using namespace std;


bool valid(char c) {
    return (c >= '0' && c <= '9');
}

int main() {
    int t = 1;
    cin >> t;
    int tt = t;
    while (t--) {
        int n;
        cin >> n;
        string a, b;
        cin >> a >> b;
        int i = 0, j = 0;
        bool flag = true;
        while (i < n && j < n) {
            if (a[i] == b[j]) i++, j++;
            else if (a[i] != '.' && b[j] != '.') {
                flag = false;
                break;
            } else if (valid(a[i]) && (a[i] - '0') % 2 == 0 && b[j] == '.') {
                if (i < n - 1 && a[i + 1] == '.') swap(a[i], a[i + 1]);
                else {
                    flag = false;
                    break;
                }
            } else if (valid(b[j]) && (b[j] - '0') % 2 == 1 && a[i] == '.') {
                if (j < n - 1 && b[j + 1] == '.') swap(b[j], b[j + 1]);
                else {
                    flag = false;
                    break;
                }
            } else {
                flag = false;
                break;
            }
        }
        if (flag) cout << "YES";
        else cout << "NO";
        cout << endl;
    }
    return 0;
}
Copy
Moving Digits Fattah
GNU G++17
51 ms
1.0 MB
Accepted