YTU 2896: J--Zipper
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.
样例输入
3
cat tree tcraete
cat tree catrtee
cat tree cttaree
样例输出
Data set 1: yes
Data set 2: yes
Data set 3: no
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include<stdio.h>
#include<string.h>
#define MAX 201
int 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;
}
#include<string.h>
#define MAX 201
int 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;
}
YTU 2896: J--Zipper的更多相关文章
- YTU 3026: 中序线索化二叉树
原文链接:https://www.dreamwings.cn/ytu3026/2896.html 3026: 中序线索化二叉树 时间限制: 1 Sec 内存限制: 128 MB 提交: 9 解决: ...
- HDU 2896 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- Zipper
Zipper Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdoj 2896 病毒侵袭(AC自动机)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 思路分析:题目为模式匹配问题,对于一个给定的字符串,判断能匹配多少个模式:该问题需要静态建树,另 ...
- HDU 1501 Zipper 动态规划经典
Zipper Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU 1501 Zipper(DP,DFS)
意甲冠军 是否可以由串来推断a,b字符不改变其相对为了获取字符串的组合c 本题有两种解法 DP或者DFS 考虑DP 令d[i][j]表示是否能有a的前i个字符和b的前j个字符组合得到c的前i+j ...
- hdu1501 Zipper
Zipper Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- Zipper(poj2192)dfs+剪枝
Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15277 Accepted: 5393 Descripti ...
随机推荐
- Action中result的各种转发类型
Action中result的各种转发类型 1,dispatcher:默认值 ,内部定向 <result>/WEB-INF/page/employeeAdd.jsp</result&g ...
- json拼接含字符串变量的问题
json键值对,当值为字符串变量时,极易搞错,拼接务必注意.String str="文字信息";String json="{\"msg\":\&quo ...
- ACM-ICPC 2018 南京赛区网络预赛 L && BZOJ 2763 分层最短路
https://nanti.jisuanke.com/t/31001 题意 可以把k条边的权值变为0,求s到t的最短路 解析 分层最短路 我们建立k+1层图 层与层之间边权为0,i 向 i+1层转 ...
- c++ 高性能日志库(muduo_AsyncLogging)
c++ 高性能日志库(muduo_AsyncLogging) 实现一个高效的网络日志库要解决那些问题? 首先明确一下问题的模型,这是一个典型的多生产者 单消费者问题,对于前端的日志库使用者来说,应该做 ...
- CSY版最大团,速度快一倍
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i(0); i < (n); ++i) ...
- 【搜索引擎】Solr最新安装以及通过关系型数据库(MySQL,Oracle,PostgreSQL)导入数据
版本号 最新的solr版本 : Solr 8.1.1下载地址:https://lucene.apache.org/solr/downloads.html solr-8.1.0.tgz for Linu ...
- SVN 学习笔记-高级操作
所谓高级操作,只是曲高和寡,其实都不怎么用的.但是关键时候,可能会很有用. 这个高级只是针对基本操作而言.有些操作可能也是比较基本的. 清除锁 有时候我们在操作的时候,可能系统崩溃了,或者SVN非正常 ...
- FlashFXP绿色版
http://www.xdowns.com/soft/1/98/2006/Soft_30927.html
- 使用图像扫描控件ScanOnWeb实现在线图像扫描
今天上网查资料,看到一篇文章,描述的是一个开发OA软件的公司解决浏览器嵌入式扫描仪编程的文章,文章描述了改OA厂商的工程师如何辛苦的克服了各种技术难题,最终实现了在线图像扫描处理,然后又在无数个不眠的 ...
- 解决cell切割线不是全屏问题
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) { [_tableView setSeparatorInset:U ...