#include<iostream> #include<string> using namespace std; int check(string a,string b,string c) { int lena=a.length(); int lenb=b.length(); int lenc=c.length(); if(lenc!=(lena+lenb))return 0; if(a=="") { if(b==""&&c=="")return 1; else if(b!=""&&c!="") { for(int i=0;i<lenb;i++) { if(b.at(i)!=c.at(i))return 0; } return 1; } else return 0; } else if(b=="") { if(c=="")return 0; else { for(int i=0;i<lena;i++) { if(a.at(i)!=c.at(i))return 0; } return 1; } } else { if(a.at(0)==c.at(0)&&b.at(0)!=c.at(0)) { return check(a.substr(1),b,c.substr(1)); } else if(b.at(0)==c.at(0)&&a.at(0)!=c.at(0)) { return check(a,b.substr(1),c.substr(1)); } else if(b.at(0)==a.at(0)&&a.at(0)==c.at(0)) { check(a.substr(1),b,c.substr(1)); return check(a,b.substr(1),c.substr(1)); } else return 0; } } int main() { string a="abc"; string b="cd"; string c="abcdc"; cout<<check(a,b,c)<<endl; system("pause"); return 0; }