Submission

Status:
[PPPPPPPPPP]

Score: 100

User: pxsit

Problemset: 04.Corretc the wodr

Language: cpp

Time: 0.021 second

Submitted On: 2025-03-31 07:57:50

#pragma GCC optimize("Ofast,fast-math,unroll-loops,no-stack-protector,unsafe-math-optimizations,inline,inline-small-functions,inline-functions")
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,sse4.2,popcnt,lzcnt,tune=native")
#define endl '\n'
#define endll cout << '\n';
#define sp ' '
#define cinn int n;cin>> n;
#define testcase int t;cin>>t;while(t--)
const int INF = 1e9;
const long long LINF = 1e18;
const int mod = 1e9+7;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int32_t main(){ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase{
        string a,b;
        cin >> a >> b;
        if(a.size() != b.size()) {cout  << "Cannot transform to " << a << endl;continue;}
        map<char,int> freq1,freq2;
        for(int i=0;i<a.size();i++){
            freq1[a[i]]++;
            freq2[b[i]]++;
        }
        if(freq1 != freq2){ cout  << "Cannot transform to " << a << endl; continue;}
        if(a == b){
            cout << 0 << endl;
            continue;
        }
        int n = a.size();
        int cnt = 0;
        for(int i=0;i<n;i++){
            if(b[i] != a[i]){
                cnt++;
                int idx = find(b.begin()+i,b.end(),a[i]) - b.begin();
                // int fidx = idx;
                // if(b[idx] == a[idx]){
                //     do{idx = find(b.begin(),b.end(),a[i]) - b.begin();}
                //     while(b[idx] == a[idx]&&fidx!=idx);
                // }
                swap(b[i],b[idx]);
            }
        }
        cout << cnt << '\n';
    }
}