我哪错了??
查看原帖
我哪错了??
1545333
jiang_shi_qi楼主2024/11/24 18:03
#include<bits/stdc++.h>
using namespace std;
char c[27] = {};
bool check(string a, string b){
    if(a == b)
        return true;
    else if(a != b){
        if(a.size() == b.size()){
            int cnt = 0;
            for(int i = 0; i < a.size(); i++){
                if(a[i] != b[i]){
                    cnt++;
                }
            }
            if(cnt >= 2){
                return false;
            }else{
                return true;
            }
        }else if(a.size() != b.size()){
            if(max(a.size(), b.size()) - min(a.size(), b.size()) >= 2){
                return false;
            }else{
                if(b.size() < a.size()){
                    for(int i = 0; i < b.size(); i++){
                        for(int j = 0; j < 26; j++){
                            string b1 = b.substr(0, i) + c[j] + b.substr(i, b.size() - i);
                            if(b1 == a){
                                return true;
                            }
                            // cout << b1 << endl;
                        }
                    }
                    return false;
                }if(b.size() > a.size()){
                    for(int i = 0; i < a.size(); i++){
                        for(int j = 0; j < 26; j++){
                            string a1 = a.substr(0, i) + c[j] + a.substr(i, a.size() - i);
                            if(a1 == b){
                                return true;
                            }
                            // cout << a1 << endl;
                        }
                    }
                    return false;
                }
            }
        }
    }
}
int main(){
    for(int i = 0; i < 26; i++){
        c[i] = 'a' + i;
    }
    int t;
    cin >> t;
    while(t--){
        string a, b;
        cin >> a >> b;
        if(check(a, b)){
            cout << "similar\n";
        }else{
            cout << "not similar\n";
        }
    }
    return 0;
}
2024/11/24 18:03
加载中...