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;
- }
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 ...
随机推荐
- Elastic-Job-Lite 源码分析 —— 作业分片策略
摘要: 原创出处 http://www.iocoder.cn/Elastic-Job/job-sharding-strategy/ 「芋道源码」欢迎转载,保留摘要,谢谢! 本文基于 Elastic-J ...
- Java关于条件判断练习--统计一个src文件下的所有.java文件内的代码行数(注释行、空白行不统计在内)
要求:统计一个src文件下的所有.java文件内的代码行数(注释行.空白行不统计在内) 分析:先封装一个静态方法用于统计确定的.java文件的有效代码行数.使用字符缓冲流读取文件,首先判断是否是块注释 ...
- Leetcode 229.求众数II
求众数II 给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素. 说明: 要求算法的时间复杂度为 O(n),空间复杂度为 O(1). 示例 1: 输入: [3,2,3] 输出: ...
- Light oj-1259 - Goldbach`s Conjecture
1259 - Goldbach`s Co ...
- CF651B-Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Free Web Application Firewall相关资料
http://www.freewaf.org/solution/#1 http://baike.soso.com/v60659982.htm
- FATE---hdu2159(二重背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1896 【留个使用priority_queue容器的样例】
感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他, ...
- java基础 3 Object通用方法(1)
Object通用方法(1) clone: 浅复制 被复制对象的所有变量都含有与原对象相同的值,而所有对其他对象的引用仍然指向原来的对象,换言之,浅复制仅仅复 ...
- 干掉H5audio音频标签的下载按钮
audio::-internal-media-controls-download-button {display:none;}audio::-webkit-media-controls {overfl ...