求助!
查看原帖
求助!
558202
gogei楼主2024/6/23 13:48
#include <bits/stdc++.h>
using namespace std;
bool check(string a, string b)
{
    if (a.size() < b.size())
        swap(a, b);
    if (a.size() - b.size() > 1)
        return 0;
    int cnt = 0;
    if (a.size() == b.size())
    {
        for (int i = 0; i < a.size(); i++)
        {
            if (a[i] != b[i])
                cnt++;
        }
        return cnt <= 1;
    }
    for (int i = 0, j = 0; i < a.size() && j < b.size(); i++, j++)
    {
        if (a[i] != b[j])
            cnt++, i++;
    }
    return cnt <= 1;
}
int t;
string a, b;
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> a >> b;
        if (check(a, b))
            cout << "similar\n";
        else
            cout << "not similar\n";
    }
    return 0;
}
2024/6/23 13:48
加载中...