CRB and String

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

Total Submission(s): 543 Accepted Submission(s): 208

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

Author

KUT(DPRK)

题意:给你两个字符串s和t,你可以在字符串s中任意选一个字符c,在该字符c后插入一个字符d(d!=c),问经过多次此操作,能否将字符串s转化成字符串t;

思路:

对于这两个字符串,要能够插入成功必须符合两个条件

1:s是t的字串

2:对于t前k个字符如果是相同的s的前k个字符也必须是相同的,否则无法插入(想想为什么??)

只要符合上面的条件就都可以转化成功

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std; typedef unsigned long long LL; const int Max = 110000; char s[Max],t[Max]; bool flag; int main()
{
int T;
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
scanf("%s",t);
flag=false;
i=0,j=0;
for(; t[i]!='\0'; i++)
{
if(!flag&&t[i]==t[0]&&s[j]!=t[i])
{
break;
}
if(t[i]!=t[0])
{
flag=true;
}
if(s[j]!='\0'&&t[i]==s[j])
{
j++;
}
}
if(t[i]=='\0'&&s[j]=='\0')
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}

CRB and String的更多相关文章

  1. HDU-5414 CRB and String

    http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不 ...

  2. 【HDOJ 1009】 CRB and String

    [HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...

  3. HDOJ 5414 CRB and String 模拟

    CRB and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  4. HDU_5414 CRB and String 【字符串】

    一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...

  5. hdu5414 CRB and String

    Problem Description CRB has two strings s and t. In each step, CRB can select arbitrary character c  ...

  6. HDU 5414 CRB and String (2015年多校比赛第10场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...

  7. HDU 5414 CRB and String (字符串,模拟)

    题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...

  8. 多校第十场1009 CRB and String题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给你两个字符串s和t,你能够在字符串s中随意选一个字符c,在该字符c后插入一个字符d(d! ...

  9. 构造 HDOJ 5414 CRB and String

    题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...

随机推荐

  1. Java基础之处理事件——选项按钮的鼠标监听器(Lottery 2 with mouse listener)

    控制台程序. 定义监听器类有许多方式.下面把监听器类定义为单独的类MouseHandler: // Mouse event handler for a selection button import ...

  2. PostgreSQL Replication之第十一章 使用Skytools(4)

    11.4 使用 londiste 复制数据 pgq是一个叫做londiste的复制工具的核心.londiste 的核心是有一个比如比Slony 更加简单,容易使用的机制.如果您在一个大的安装中使用Sl ...

  3. manacher 最长回文子串

    确定当前已知能匹配到的最长处,看是否要更新最长 #include <bits/stdc++.h> using namespace std; const int N = 210005; in ...

  4. cpp quiz

    // ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream&g ...

  5. SQL静态

    静态 1.普通成员普通成员都是属于对象的用对象调用 2.静态成员静态成员是属于类的用类名调用 class FenBi{public int length;//普通成员public string col ...

  6. javascript 判断浏览器的ie版本,替换html标签

    /* var browser=navigator.appName var b_version=navigator.appVersion var version=b_version.split(&quo ...

  7. HDU 3308 LCIS(线段树)

    Problem Description Given n integers.You have two operations:U A B: replace the Ath number by B. (in ...

  8. springday03-go1

    springday02项目下新建包annotation11.复制xml文件到包annotation1下,并添加组件扫描方式代码2.Waiter类实现序列化接口,构造函数,并使用特定注解标记waiter ...

  9. struts局部、全局类型转换器

    第01步:编写bean package com.self.bean; import java.util.Date; public class User { private Date birthday ...

  10. mac office

    弄了个office2016正式版的教程,大多数朋友表示搞不懂,SO重新写了个超级详细的,在不懂我也是醉了.Mac office 2016免费安装教程微软近日正式向 Office 365 订阅用户发布了 ...