两个字符串找相同的子字符串,第一次用substr函数
第一个参数起始位置,第二个参数复制的长度
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
string a,b,s;
cin>>a>>b;
int flag = 0;
if(a[0] == b[0]) {cout<<"YES"<<endl<<a[0]<<"*"<<endl;flag = 1;}
else if(a[a.size()-1] == b[b.size()-1]) {cout<<"YES"<<endl<<"*"<<a[a.size()-1]<<endl;flag = 1;}
else
{
for(int i = 0 ; i < a.size() - 1 ; i++)
{
s = a.substr(i,2);
if(b.find(s) != string :: npos){cout<<"YES"<<endl<<"*"<<s<<"*"<<endl;flag = 1;break;}
}
}
if(flag == 0) cout<<"NO"<<endl;
}
return 0;
}