题解
2025-04-28 18:46:11
发布于:四川
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
bool is_similar(string a, string b) {
if (a == b) return true;
int la = a.size(), lb = b. size();
if (la == lb) {
int cnt = 0;
for (int i = 0; i < la; i++) {
if (a[i] != b[i]) {
cnt++;
if (cnt > 1) return false;
}
}
return true;
}
else if (abs(la - lb) == 1) {
if (la < lb) {
swap(a, b);
swap(la, lb);
}
int cnt = 0;
for (int i = 0, j = 0; i < la && j < lb;) {
if (a[i] == b[j]) {
i++, j++;
}
else {
i++, cnt++;
if (cnt > 1) return false;
}
}
return true;
}
else return false;
}
int main() {
int t;
cin >> t;
while (t--) {
string a, b;
cin >> a >> b;
if (is_similar(a, b)) cout << "similar" << endl;
else cout << "not similar" << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个