全wa,求助
查看原帖
全wa,求助
1071516
isop楼主2024/4/16 20:03
#include<bits/stdc++.h>
using namespace std;

bool match(string a,string b)
{
	int length=a.length()-b.length();
	
	if(a==b) return true;
	else if(length>=2 || length<=-2)
	{
		//cout<<"1"<<endl;
        return false;
	}
	else
	{
		if(a.length()==b.length())
		{
			int num;
			for(int i=0;i<a.length();i++)
				if(a[i]!=b[i]) num++;
			if(num>1)
			{
			    //cout<<"2"<<endl;
                return false;
			}
			else return true; 
		}
		
		string l,s;
		if(a.length()>b.length())  l=a,s=b;
		else l=b,s=a;

		int tem=0,ans=0,num=0;
		while(tem<l.length() && ans<s.length())
		{
			if(s[ans]!=l[tem])
			{
				tem++;
				num++;
				if(num>1)
				{
					//cout<<"3"<<endl;
	                return false;
				}
			}
			else ans++,tem++;
		}
		return true;
	}
}

int main()
{
	string a,b;
	int t;
	cin>>t;
	while(t)
	{
		cin>>a>>b;
		if(match(a,b)) cout<<"similar"<<endl;
		else cout<<"not similar"<<endl;
		t--;
	}
}
2024/4/16 20:03
加载中...