re求助
查看原帖
re求助
663295
ruruo楼主2024/10/7 19:40
#include<bits/stdc++.h>
using namespace std;

bool chk(string a, string b) {
	int s1 = a.size(), s2 = b.size();
	if(abs(s1 - s2) >= 2)
		return false;
	if(s1 == s2) {
		int cnt = 0;
		for(int i = 0; i < s1; i++)
			if(a[i] != b[i]) cnt++;
		return cnt <= 1;
	}
	if(s1 < s2)
		swap(a, b);
	for(int i = 0; i <= s2; i++)
		for(char c = 'a'; c <= 'z'; c++) {
			string tmp = b;
			tmp.insert(i, 1, c);
			// cout << tmp << endl;
			if(a == tmp) return true;
		}
	return false;
}

int main() {
    int Q;
    cin >> Q;
    while(Q--) {
        string a, b;
        cin >> a >> b;
        cout << (chk(a, b) ? "similar\n" : "not similar\n");
    }
    return 0;
}
2024/10/7 19:40
加载中...