Description

Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.

For example, consider forming "tcraete" from "cat" and "tree":

String A: cat 
String B: tree 
String C: tcraete

As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":

String A: cat 
String B: tree 
String C: catrtee

Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".

Input

The first line of input contains a single positive integer from 1 through 1000. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, one data set per line.

For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive.

Output

For each data set, print:

Data set n: yes

if the third string can be formed from the first two, or

Data set n: no

if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.

Sample Input

3
cat tree tcraete
cat tree catrtee
cat tree cttaree

Sample Output

Data set 1: yes
Data set 2: yes
Data set 3: no

【题意】给出三个字符串,求前两个是否包含在第三个中。

【思路】之前用过dfs,这次用dp,检验dp[len1][len2]是否为1;

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int dp[N][N];
int main()
{
int n;
char a[N],b[N],c[N];
int cas=;
while(~scanf("%d",&n))
{
cas++;
memset( dp,,sizeof(dp));
scanf("%s%s%s",a+,b+,c+);
int len1=strlen(a+);
int len2=strlen(b+);
int len3=strlen(c+);
for(int i=;i<=len1;i++)
{
if(a[i]==c[i]) dp[i][]=;
else break;
}
for(int j=;j<=len2;j++)
{
if(b[j]==c[j])
dp[][j]=;
else break;
}
for(int i=;i<=len1;i++)
{
for(int j=;j<=len2;j++)
{
if(c[i+j]==a[i]&&dp[i-][j])
dp[i][j]=;
if(c[i+j]==b[j]&&dp[i][j-])
dp[i][j]=;
}
}
printf("Data set %d: ",cas);
if(dp[len1][len2]) printf("yes\n");
else printf("no\n");
}
return ;
}

最新文章

  1. 【小白的CFD之旅】14 实例反思
  2. Android_layout 布局(二)
  3. 线段树 hdu4046
  4. hdu-5495 LCS(置换)
  5. AVL树的旋转实现
  6. informatica9.5.1资源库为machine in exclusive mode(REP_51821)
  7. C++ Code_ScrollBar
  8. js判断一个变量是否为数组的解决方案
  9. 交换机Trunk端口配置
  10. 运维自动化之SALTSTACK简单入门
  11. SqlSessionFactoryBuilder、SqlSessionFactory、SqlSession作用域(Scope)和生命周期
  12. C#面试题整理(1)
  13. 干了这杯Java之HashMap
  14. win2008 401 - 未授权: 由于凭据无效,访问被拒绝。解决方法
  15. js里面对数据处理的方法
  16. Navicat操作SQL server 2008R2文件.bak文件还原
  17. SqlServer执行Insert命令同时判断目标表中是否存在目标数据
  18. Android开发 - 掌握ConstraintLayout(二)介绍
  19. 微服务(Microservices )简介
  20. Easyui datagrid绑定数据,新增,修改,删除方法(一)

热门文章

  1. (转)codeblock(常用快键)
  2. java代码抓取网页邮箱
  3. 大作业关于(“有爱”youi)的简介
  4. netty4 连通步骤
  5. Octopus系列之开发过程各个技术点
  6. double int char 数据类型
  7. 使用MediaRecorder录制视频短片
  8. 原生JS 添加或者删除某个class
  9. ASP.NET备份还原数据库
  10. 用户列表-投资记录sql