您的位置:首页 > 其它

HDU 5414 CRB and String

2015-08-20 20:50 330 查看


CRB and String

Time Limit: 2000/1000 MS (Java/Others) Memory Limit:
65536/65536 K (Java/Others)

Total Submission(s): 257 Accepted Submission(s): 93



Problem Description

CRB has two strings s and t.

In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.

CRB wants to convert s to t.
But is it possible?



Input

There are multiple test cases. The first line of input contains an integer T,
indicating the number of test cases. For each test case there are two strings s and t,
one per line.

1 ≤ T ≤ 105

1 ≤ |s| ≤ |t| ≤ 105

All strings consist only of lowercase English letters.

The size of each input file will be less than 5MB.



Output

For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".



Sample Input

4
a
b
cat
cats
do
do
apple
aapple




Sample Output

No
Yes
Yes
No
给你一个s串 和 t串 ,可以在s串每个字符s[i]的后面插入任意一个字符d (要求这时的d 不能与s[i]相同)比如 由"aa" 变为"asaa"  这个过程为 aa -> asa(在'a'的后面插入's') -> asaa(s后面再插入a)其中一点比较特殊的是 "aa" 可以变为"aasaa" ,过程如下"aa" -> "aas" -> "aasa" -> "aasaa"这样一看我们最后一个'a'前面也是个'a',其实这个'a'是在's'后插入的 ,即一个字符s[i]后可以重复多次插入与s[i]不同的 相同的字符 ,说的有点绕 ,其实就是在这个's'后可以重复的插入同一个字符'a'。。还有一点是 s[0] 前面是不能插入字符的  aa 是不能变成 taa的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#define inf 0x3f3f3f3f
#define N 100001
using namespace std;
char s
,t
;
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%s%s", s, t);
        int lens = strlen(s);
        int lent = strlen(t);
        int k = 0;
        for(int i = 0; i < lent; i++)  // 判断串s中是否含有 t串中不存在的字符
        {
            if(t[i] == s[k])           //s串中字符不能删除 ,如果有直接No
                k++;
            if(k == lens) break;
        }
        if(k < lens || s[0] != t[0])   //首字符不同输出No s串首不能插入 
        {
            printf("No\n");
            continue;
        }
        int ss = 0;
        int tt = 0;
        while(ss < lens)
        {
            if(s[ss] == s[0] && t[tt] == t[0])   //找出s串 和 t 串的公共相同前缀 
            {
                ss++;                            // 如 s : aa     t : aaataa     
                tt++;                            // 公共前缀为 aa
            }                                   //此时若 t串的下一个字符还与前缀字符相同
            else break;                         //即说明s不可能变为t
        }                                       // 因为 aa 无法 变为 aaa
        if(t[tt] == s[0])
         printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: