博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
YTU 2896: J--Zipper
阅读量:4679 次
发布时间:2019-06-09

本文共 2911 字,大约阅读时间需要 9 分钟。

2896: J--Zipper

时间限制: 1 Sec  
内存限制: 128 MB
提交: 29  
解决: 15

题目描述

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".

输入

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.

输出

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.

样例输入

3cat tree tcraetecat tree catrteecat tree cttaree

样例输出

Data set 1: yesData set 2: yesData set 3: no

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include
#include
#define MAX 201int opt[MAX][MAX];int main(){ int n; int cnt=0; char str1[MAX],str2[MAX],str3[MAX*2]; int len_str1,len_str2,len_str3; int i,j; scanf("%d",&n); while(n--) { cnt++; scanf("%s %s %s",str1,str2,str3); len_str1=strlen(str1); len_str2=strlen(str2); len_str3=strlen(str3); if(len_str1+len_str2!=len_str3) { printf("Data set %d: no\n",cnt); continue; } memset(opt,0,sizeof(opt)); opt[0][0]=1; for(i=1; i<=len_str1; i++) { if(opt[i-1][0]==1&&str1[i-1]==str3[i-1]) opt[i][0]=1; else break; } for(j=1; j<=len_str2; j++) { if(opt[0][j-1]==1&&str2[j-1]==str3[j-1]) opt[0][j]=1; else break; } for(i=1; i<=len_str1; i++) { for(j=1; j<=len_str2; j++) { if((opt[i][j-1]==1&&str2[j-1]==str3[i+j-1])||(opt[i-1][j]==1&&str1[i-1]==str3[i+j-1])) opt[i][j]=1; } } if(opt[len_str1][len_str2]) printf("Data set %d: yes\n",cnt); else printf("Data set %d: no\n",cnt); } return 0;}

转载于:https://www.cnblogs.com/im0qianqian/p/5989614.html

你可能感兴趣的文章
格网与四叉树索引
查看>>
多张照片拍摄、图片浏览
查看>>
html(5) css
查看>>
Azure Web连接到Azure MySql Db
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
leetcode-17-电话号码的字母组合’
查看>>
Flume 示例
查看>>
Designing for Performance
查看>>
HTML属性的应用
查看>>
HEAP CORRUPTION DETECTED
查看>>
Android URI简单介绍
查看>>
蒙板 模态对话框
查看>>
pythong中的全局变量的调用和嵌套函数中变量的使用
查看>>
【POJ - 3009】Curling 2.0 (dfs+回溯)
查看>>
Windows下载安装良心教程
查看>>
浅析商业银行“业务连续性管理体系”的构建
查看>>