64,639
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
using namespace std;
bool fun2(const string& s1,int pos1,const string& s2,int pos2,const string& s3,int pos3){
if(pos1==s1.size()&&pos2==s2.size()&&pos3==s3.size())return true;
else if((pos1==s1.size()&&(pos2<s2.size()||pos3<s3.size()))||s1[pos1]!=s2[pos2]&&s1[pos1]!=s3[pos3])return false;
int p1=pos1,p2=pos2,p3=pos3;
bool f1,f2;
while(p1<s1.size()&&p2<s2.size()&&s1[p1]==s2[p2])
++p1,++p2;
f1=fun2(s1,p1,s3,p3,s2,p2);
if(f1)return true;
p1=pos1,p2=pos2;
while(p1<s1.size()&&p3<s3.size()&&s1[p1]==s3[p3])
++p1,++p3;
if(p1==pos1)return false;
f2=fun2(s1,p1,s2,p2,s3,p3);
if(f1||f2)return true;
return false;
}
void fun1(const string& s1,const string& s2,const string& s3){
bool f=fun2(s1,0,s2,0,s3,0);
if(f)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main(){
string s1="aa";
string s2="a";
string s3="ab";
fun1(s1,s2,s3);
return 0;
}
while(*strs)
{
if(*strs==*strc1)
++strc1;
else if(*strs==*strc2)
++strc2;
else
{
cout<<"NO";
return 0;
}
++strs;
}
if(*strc1==0&&*strc2==0)
cout<<"YES";
else
cout<<"NO";
#include <iostream>
#include <string>
using namespace std;
bool _findString(const string &first,const string &second,const string &object,size_t pos1,size_t pos2,size_t pos3)
{
if(pos3==object.size())
{
return true;
}
bool isFound=false;
if(pos1!=first.size() && first[pos1]==object[pos3])
{
isFound=isFound||_findString(first,second,object,pos1+1,pos2,pos3+1);
}
else
{
size_t pos=pos2;
while(pos!=second.size() && second[pos]!=object[pos3])
{
++pos;
}
if(pos!=second.size())
{
isFound=isFound||_findString(first,second,object,pos1,pos+1,pos3+1);
}
}
return isFound;
}
bool findString(const string &first,const string &second, const string &object)
{
return _findString(first,second,object,0,0,0);
}
int main()
{
string first,second,object;
cin>>object>>first>>second;
cout<<findString(first,second,object)<<endl;
return 0;
}