Untitled

Anonymous
plain_text
10/03/2026 4:13 PM
1.8 KB
2
Indexable
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
void testCase()
{
    string a,b;
    cin>>a>>b;
 
    vector <int> v;
    int counter=0;
 
    if(a.length()!=b.length()){
        cout<<"NO\n";
        return;
    }
 
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            v.push_back(i);
            counter++;
        }
    }
 
    if(counter==0){
        int freq[10001]={};
        bool is=false;
        for(int i=0;i<a.size();i++){
            freq[a[i]]++;
        }
 
        for(int i=0;i<10001;i++){
            if(freq[i]>1){
                is=true;
                break;
            }
        }
        if(is){
            cout<<"YES\n";
            return;
        }
        else{
            cout<<"NO\n";
            return;
        }
    }
 
    else if(counter>2 || counter==1){
        cout<<"NO\n";
        return;
    }
    else if(counter==2){
        if(a[v[0]]==b[v[1]] && a[v[1]]==b[v[0]]){
            cout<<"YES\n";
            return;
        }
        else{
            cout<<"NO\n";
            return;
        }
    }
 
 
}
 
 
 
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t=1;
    //cin>>t;
 
    while(t--){
        testCase();
    }
    
    
    
    return 0;
}
Editor is loading...
Leave a Comment