Untitled

Anonymous
plain_text
10/03/2026 3:48 PM
1.5 KB
2
Indexable
#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    string A, B;
    cin >> A >> B;
    if (A.size() != B.size())
    {
        cout << "NO";
        return 0;
    }
   
    vector<int>vIndex;
    for (int i = 0; i < A.size(); i++)
    {
        if (A[i] != B[i])
        {
            vIndex.push_back(i);
        }
    }
    if (vIndex.size() == 2)
    {
        swap(A[vIndex[0]], A[vIndex[1]]);
        if (A == B)
        {
            cout << "YES";
            return 0;
        }
        else
        {
            cout << "NO";
            return 0;
        }
    }
    else if(vIndex.size()>2||vIndex.size()==1)
    {
        cout << "NO";
        return 0;
    }
    else
    {
        string temp = A;
        sort(temp.begin(), temp.end());

        for (int i = 0; i < temp.size() - 1; i++)
        {
            if (temp[i] == temp[i + 1])
            {
                cout << "YES";
                return 0;
            }
        }

        cout << "NO";
        return 0;
    }
    return 0;
}
Editor is loading...
Leave a Comment