Zipper

2023-10-31

http://poj.org/problem?id=2192

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


**********************************************************
#include<stdio.h>
#include<string.h>
#define NN 405
char s1[NN],s2[NN],s3[NN];
int m,len1,len2,len3,flag;
void DFS(int x,int y,int z)
{
if(z>=len3)
{
flag=1;
return;
}
if(flag)
{
return;
}
if(s1[x]!=s3[z]&&s2[y]!=s3[z])
{
return;
}
if(s1[x]==s3[z]&&x<len1)
   DFS(x+1,y,z+1);
    if(s2[y]==s3[z]&&y<len2)
        DFS(x,y+1,z+1);

}
int main()
{
int i,j;
scanf("%d",&m);
for(i=1;i<=m;i++)
{
flag=0;
scanf("%s %s %s",s1,s2,s3);
len1=strlen(s1);
len2=strlen(s2);
len3=strlen(s3);
printf("Data set %d: ",i);
if(s1[len1-1]!=s3[len3-1]&&s2[len2-1]!=s3[len3-1])//实际上不要这步判断也是可以的但会超时。
{
printf("no\n");
continue;
}
if(len1+len2!=len3)
{
printf("no\n");
continue;
}
DFS(0,0,0);
if(flag==0)
  printf("no\n");
        else
           printf("yes\n");
}
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Zipper 的相关文章

随机推荐

  • 【Linux】——makefile

    文章目录 1 什么是makefile 2 makefile优势与make命令 3 makefile文件内容 3 1makefile文件的基础写法 3 2 makefile文件的优化 1 什么是makefile 在一个大型工程中 工程中的源文
  • 构建Python,Raspberry Pi和PostgreSQL数据服务器

    视频教程 PostgreSQL初学者 学习Raspberry Pi Linux初学者指南 在Raspberry Pi安装和设置PostgreSQL 前提 下载Raspbian 格式化SD卡 使用Disk Utility在macOS中格式化S
  • 自制番茄钟脚本

    Shell脚本 bin bash i 0 if 1 then t 25 60 else t 5 60 fi while i lt t do sleep 1 i 1 m t i 60 s t m 60 i echo en m s r done
  • parsing XML document from class path resource [applicationContext.xml]…

    方法 1 可能是缺失了resource文件 项目右键 Build Path Configure Build Path Java Build Path source Add Folder 将Resource添加应用 2 可能缺失了spring
  • SqliLab_Mysql_Injection详解_字符型注入(五)_时间盲注(8~10)

    文章目录 1 SqliLab Mysql Injection详解 字符型注入 五 1 1 SQL注入 时间盲注 1 1 1 原理 1 1 2 常用的函数 2 SqliLab关卡 包含8 9 10 图片占据空间太大 payload具体返回情况
  • [从零学习汇编语言] - 模块化程序设计

    文章目录 前言 回顾 一 模块化程序设计 1 1 子程序 1 2 子程序的参数和返回值 1 3 批量数据的传递 1 4 寄存器的冲突处理 结语 前言 点赞再看 养成习惯 回顾 还记得我们之前讲过的ret指令搭配call指令实现的子程序模板吗
  • SpringCache通过注解实现redis缓存

    1 SpringCache介绍 2 SpringCache常用注解 底层是基于map实现的 缺点 重启后数据就不存在了 在Spring Cache使用方式中将底层实现替换成了redis缓存技术 1 CachePut 参考演示 CachePu
  • Loading自定义指令

    目录 Loading自定义指令 一 介绍 二 自定义指令及使用 1 创建loading组件 2 自定义指令 3 main js中全局注册 4 使用 三 结果演示 Loading自定义指令 相关知识查看官方文档 自定义指令 一 介绍 通过v
  • mysql5.5 导入 mysql5.6 或者 mysql 5.7 的sql文件失败

    今天导入数据库的时候 一直失败 发现是mysql版本的问题 唉 难道不能向下兼容嘛 下面说解决方案 第一步 用nodepad 打开sql文件 第二部 按照下面方式进行全文替换 代表任意数字字符 datetime gt datetime TI
  • 一线大厂:从需求提出到上线流程总结

    在一线大厂 从需求提出到上线 整个流程是怎样的 笔者结合腾讯的工作流和调研了阿里 字节等公司的项目开发流程 发现大厂的工作流大同小异 总结了如下的整体流程图 下面将按照这个流程的每个节点 详细阐述 全文3000多字 阅读大概需要6分钟 目录
  • Struts2的国际化文件配置样式以及中文字体设置

    我来填坑划水来了 这次讲的是我在工程中通过在国际化文件中来设置样式 这样页面调用国际化的话 不用在页面控制字体样式 那国际化文件文件怎么设置字体样式呢 其实很简单就是用HTML实例 虽然我还没找到资料证明是HTML实例 只是按照工程常遇见的
  • Python深度学习实战PyQt5信号与槽的连接

    本文讲解信号与槽的连接机制 详细示范各种类型的信号 槽连接的实现方法 这是图形用户界面的核心内容 还将介绍面向对象的程序设计 这是图形用户界面的基本思想 目录 1 信号与槽 Signals and slots 信号与槽机制是 PyQt 的核
  • 《七》JavaScript 中的运算符和表达式

    运算符的综合运算顺序是 非运算符 gt 算术运算符 gt 比较运算符 gt 逻辑运算符 3 gt 2 8 gt 3 4 true 首先计算 3 4 等于 7 然后比较 3 gt 2 为 true 再比较 8 gt 7 为 true 最后 t
  • Ubuntu的终端重启命令

    Ubuntu的终端重启命令 终端命令重启 终端命令重启 自己记录一下 懒得搜了 shutdown h now 立即关机 shutdown h xx xx 到xx xx 具体时间 关机 如果该时间小于当前时间 则到隔天 shutdown h
  • Obsidian&FolderSync 创作格外丝滑

    简介 Obsidian is a powerful knowledge base on top of a local folder of plain text Markdown files A second brain for you fo
  • 命令...

    1 Git git stash 暂存本地的修改 git pull git branch a 可以查看所有本地分支和远程分支 git branch r 只查看远程分支 git fetch 在项目中更新gitlab上创建的分支 git push
  • 商城小程序源码开发搭建

    前言 随着移动互联网的快速发展 小程序成为了一种受欢迎的移动应用形式 在这一趋势下 商城小程序应运而生 为企业和个人提供了一种全新的商业模式 本文将重点介绍商城小程序源码及其应用价值 并为您提供几个常用的商城小程序源码示例 第一部分 商城小
  • vue使用elment的弹窗里面调用AMap.Autocomplete提示失效

    1 使用AMap Autocomplete提示失效 不是加载失效 是被弹窗的层级挡住了 这里面涉及到用了elment ui 的模态窗组件 我在自定义组件内通过深度选择器也没效果 需要全局引入 amap sug result z index
  • 【C语言】指针的定义、概念和运用

    一 地址和指针的概念 问题 数据在内存中是如何存储和读取的 在程序中定义一个变量后 在对程序编译的时候 系统就会给这个变量分类内存单元 编译系统根据程序中定义的变量类型 分配一定长度的空间 例如 一般整型为2个字节 单精度浮点类型分类4个字
  • Zipper

    http poj org problem id 2192 Description Given three strings you are to determine whether the third string can be formed