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. sql语句感想

    select出来内容可以当成表拿来用,,比如取别名什么的. union是纵向的,追加记录(行) join on是横向的,追加列

  2. Java Servlet(一):创建工程(jdk7+tomcat7+eclipse)

    本篇文件主要记录下怎么在jdk7+tomcat7下,使用eclipse创建并运行一个servlet工程. 安装具体步骤从网上搜索就可以找到,这里不再赘述. 在eclipse中切换到j2ee下, 从导航 ...

  3. Azure billing 分析

    昨天把西欧的2012的VM删掉,在北美新建一个2008的VM,装了sql2005 express 在C盘,这样存储就变成2个位置了,西欧和美国,然后放在那里不操作一天,发现billing多了很多, S ...

  4. PostgreSQL与RPM

    如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/us ...

  5. Leetcode: Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  6. 转:python webdriver API 之 获取对象的属性

    获取测试对象的属性能够帮我们更好的进行对象的定位.比如页面上有很多标签为 input 元素,而我们需要定位其中 1 个有具有 data-node 属性不一样的元素.由于 webdriver 是不支持直 ...

  7. CSS自定义弹出框

    <script type="text/javascript" language="javascript"> function sAlert(str) ...

  8. 【Origin】jquery.barddialog.js

    /// <reference path="jquery-2.1.1.min.js" /> /** * @license jquery.bardDialog 1.0.0 ...

  9. ASP.NET的一般处理程序对数据的基本操作

    TableList.ashx: <%@ WebHandler Language="C#" Class="TableList" %> using Sy ...

  10. oracle冷备份后恢复

    本地恢复 在运行中输入cmd. 在cmd界面中输入sqlplus/nolog进入sql*plus. 以dba身份连接数据库conn sys/你设定的密码 as sysdba. 输入:shutdown ...