POJ 2192

简介: Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13041   Accepted: 4560 Description Given three strings, you ...
Zipper
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13041   Accepted: 4560

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>
char str1[210],str2[210],str[420];
bool vis[210][210];
bool dp(char *str1,char *str2,char *str)//原来把参数顺序传错啦
{
    int i,j;
    int len1=strlen(str1);
    int len2=strlen(str2);
    int len=strlen(str);
    if(len1+len2!=len)
        return false;
    for(i=1;i<=len1;i++)
        vis[i][0]=false;
    for(i=1;i<=len2;i++)
       vis[0][i]=false;
    vis[0][0]=true;
    for(i=0;i<=len1;i++)
        for(j=0;j<=len2;j++)
        {
            if(i>0&&str1[i-1]==str[i+j-1]&&vis[i-1][j])
                vis[i][j]=true;
            if(j>0&&str2[j-1]==str[i+j-1]&&vis[i][j-1])
                vis[i][j]=true;
        }
    return vis[len1][len2];
}
int main()
{
    int i,j,T;
    bool flag;
    scanf("%d%*c",&T);
    j=1;
    while(T--)
    {
        memset(str,0,sizeof(str));
        memset(str1,0,sizeof(str1));
        memset(str2,0,sizeof(str2));
        memset(vis,0,sizeof(vis));
        scanf("%s",str1);
       // puts(str1);
        scanf("%s",str2);
       // puts(str2);
        scanf("%s",str);
      //  puts(str);          
        flag=dp(str1,str2,str);
        /*
        for(i=0;i<15;i++)
        {  
             for(j=0;j<15;j++)
                 printf("%d ",vis[i][j]);
            putchar('\n');
        }
        */
        printf("Data set %d: %s\n",j++,flag==true?"yes":"no");
    }
    return 0;
}

 

目录
相关文章
|
5月前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
|
5月前
|
算法 数据建模
Poj 3169(差分约束系统)
Poj 3169(差分约束系统)
34 0
|
12月前
poj 3298 数状数组
题目大意是一条大街上住着n个乒乓球爱好者,他们的水平高低用一个数值表示,他们经常举办比赛,比赛要三个人,一人当裁判。对裁判是有一定要求的,裁判的水平必须介于两选手之间且必须住他们中间,计算可以举办多少场比赛
40 0
|
算法 数据建模 机器学习/深度学习
poj-1008-玛雅历
Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现。从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法。这个Haab历法拥有19个月,在开始的18个月,一个月有20天,月份的名字分别是pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu。
878 0
|
存储
大数加法-poj-1503
poj-1503-Integer Inquiry Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking vari
1117 0
poj 1456 Supermarket
点击打开链接poj 1456 思路: 贪心+并查集 分析: 1 题目的意思是给定n个物品的利润和出售的最后时间,求最大的利润 2 比较明显的贪心问题,按照利润排序,假设当前是第i个物品,那么利润为pi出售的时间为di,那么假设di还没有物品销售那么肯定先销售第i个物品,否则找di~1这些时间里面是否有没有销售物品 3 如果按照2的思路做法最坏的情况是O(n^2),但是数据比较弱可以过。
809 0