题解
2025-05-08 19:03:18
发布于:四川
7阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
bool is_sim(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(lb > la){
swap(a, b);
swap(la, lb);
}
int i = 0, j = 0, cnt = 0;
while(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 n;
string a, b;
cin >> n;
while(n--){
cin >> a >> b;
if(is_sim(a, b)) cout << "similar" << endl;
else cout << "not similar" << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个