不太明白自己的这个写法为啥会全wa,哭(看大佬的题解已经ac了),求看代码~
查看原帖
不太明白自己的这个写法为啥会全wa,哭(看大佬的题解已经ac了),求看代码~
1250606
saurrrry楼主2024/7/3 10:32
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        string a,b;
        cin>>a>>b;
        int sa = a.size(),sb = b.size();
        if(sa > sb) swap(a,b);
        if(sb - sa >=2) {
            cout<<"not similar"<<endl;
        }
        else if(sa == sb){
            int ch = 0;
            for(int j=0; j<sa; j++){
                if(a[j] != b[j]) ch++;
            }
            if(ch<=1) cout<<"similar"<<endl;
            else cout<<"not similar"<<endl;
        }
        else{
            for(int j=0;j<sa;j++){
                if(a[j] != b[j]) {
                    b.erase(j,1);
                    break;
                }
            }
            if(a == b || b.size()-a.size() == 1) cout<<"similar"<<endl;
            else cout<<"not similar"<<endl;
            //AC做法
            // int ans = 0,f = 0;
        //     for(int j=0;j<sa;j++){
        //         if(a[j] != b[j]) {
        //             ans = 1;
        //         }
        //         if(ans&&b[j+ans]!=a[j]){
        //             f = 1;
        //             cout<<"not similar"<<endl;
        //             break;
        //         }
        //     }
        //     if(f == 0) cout<<"similar"<<endl;
        }
    }
}
2024/7/3 10:32
加载中...