Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=850;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--){
        vector<int>a[11],b[11];
        int n;
        string s,t,x,y;
        cin>>n;
        cin>>s;
        cin>>t;
        for(int i=0;i<n;i++){
            if(s[i]!='.'){
                a[s[i]-'0'].push_back(i);
                x+=s[i];
            }
            if(t[i]!='.'){
                b[t[i]-'0'].push_back(i);
                y+=t[i];
            }
        }
        if(x!=y){
            cout<<"no"<<'\n';
            continue;
        }
        bool ok=true;
        for(int j=0;j<=9;j++){
            for(int i=0;i<b[j].size();i++){
                if(j%2==0){
                    if(b[j][i]<a[j][i])ok=false;
                }
                if(j%2==1){
                    if(b[j][i]>a[j][i])ok=false;
                }
            }
        }
        cout<<(ok?"yes":"no")<<'\n';
    }   
}
Copy
Moving Digits Ahmed_Allawati
GNU G++17
20 ms
2.6 MB
Accepted