Problem Description
Given three strings a, b and c, your mission is to check whether c is the combine string of a and b.
A string c is said to be the combine string of a and b if and only if c can be broken into two subsequences, when you read them as a string, one equals to a, and the other equals to b.
For example, `adebcf'' is a combine string of`abc'' and ``def''.

Input
Input file contains several test cases (no more than 20). Process to the end of file.
Each test case contains three strings a, b and c (the length of each string is between 1 and 2000).

Output
For each test case, print `Yes'', if c is a combine string of a and b, otherwise print`No''.

Sample Input
abc
def
abc
def
abecdf

Sample Output
Yes
No

4个回答

``````int res=0;
a='ab'
b='ac'
c='acab'
void f(int ai,int bi,int ci){
if(ai+bi+ci== a.len+b.len+c.len-1){ res=1; return;}
if(ai==a.len or bi==b.len or ci==c.len) return;
if(a[ai]==c[ci]) f(ai+1,bi,ci+1);
if(a[bi]==c[ci]) f(ai,bi+1,ci+1);
}
int main(){
f(0,0,0);
print(res);
}
``````

Moluth 大兄弟，你这回答，真是胡闹，该问题不是这么简单的

a，从另外两个头部出a，有继续，没有就是NO

``````
public class Test {
public static void main(String args[]) {
System.out.println(combine("ab", "ac", "acab"));
}

public static boolean combine(String a, String b, String c) {
if (a.length() == 0) {
return b.equals(c);
} else if (b.length() == 0) {
return a.equals(c);
}
char cha = a.charAt(0), chb = b.charAt(0), chc = c.charAt(0);
if (cha == chc && chb == chc) {
return combine(a.substring(1), b, c.substring(1))
|| combine(a, b.substring(1), c.substring(1));
} else if (cha == chc) {
return combine(a.substring(1), b, c.substring(1));
} else if (chb == chc) {
return combine(a, b.substring(1), c.substring(1));
}
return false;
}
}

``````
miaoch 回复Moluth: 改了一下 应该没问题了，非空判断什么的就先不写了

miaoch 回复Moluth: 恩 是的，没注意

Moluth 兄弟呀，你这个明显不行的，例如：a='ac' b='ab' c='abac' 安照你的代码，很明显会返回false的，实际结果是true