http://acm.hdu.edu.cn/showproblem.php?pid=5414

题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不能将s变为t。

分析:只要前面t串连续的字符==s字符串,而且保证s是t的子串。本来想不通s:aabaa,t:aabaaaa,后面四个a怎么插,后来才想明白,后面的a都可以插在b后面,就可以了。

CRB and String

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 676 Accepted Submission(s):
256

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)
 
Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; char s[],t[];
int main()
{
int r;
scanf("%d",&r);
getchar();
while(r--)
{
int i,j;
scanf("%s",s);
scanf("%s",t);
int len1=strlen(s);
int len2=strlen(t);
int flag=;
for(i=;i<len2;i++)
if(t[i]!=t[])
break;//找到t串的第一个不连续的位置
for(j=;j<i;j++)//看s的前i个子串是否连续
if(s[j]!=t[j])
{
flag=;
break;
}
j=i;
for(;j<len1;j++)
{
for(;i<len2;i++)
{//找到下一个和s相等的地方
if(t[i]==s[j])
break;
}
if(i==len2)
{
flag=;
break ;//如果t找完了还没跳出证明s不是t的子串
}
i++;
}
if(s[]!=t[])
flag=;
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return ;
}

HDU-5414 CRB and String的更多相关文章

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

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

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

    题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是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. 构造 HDOJ 5414 CRB and String

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

  5. HDU 5842 Lweb and String(Lweb与字符串)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  6. CRB and String

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

  7. hdu 4850 Wow! Such String! 欧拉回路

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...

  8. hdu 3553 Just a String (后缀数组)

    hdu 3553 Just a String (后缀数组) 题意:很简单,问一个字符串的第k大的子串是谁. 解题思路:后缀数组.先预处理一遍,把能算的都算出来.将后缀按sa排序,假如我们知道答案在那个 ...

  9. Hdu 5416 CRB and Tree (bfs)

    题目链接: Hdu 5416 CRB and Tree 题目描述: 给一棵树有n个节点,树上的每条边都有一个权值.f(u,v)代表从u到v路径上所有边权的异或值,问满足f(u,v)==m的(u, v) ...

随机推荐

  1. lispbox 安装运行.sh的时候出现 lispbox.sh: 2: lispbox.sh: Bad substitution

    安装lispbox时使用tar命令将压缩文件解压之后cd进入之后在运行.sh文件时出现了如下情况. $ sh lispbox.sh lispbox.: lispbox.sh: Bad substitu ...

  2. PHP的PSR-0命名标准

    PSR是Proposing a Standards Recommendation(提出标准建议)的缩写,是由PHP Framework Interoperability Group(PHP通用性框架小 ...

  3. 原生js在IE7下 向dom添加节点的一个bug, (本例为添加hidden input)

    需求是要用js向dom结构增加1个hidden用来存放要post到服务器的数据 var aspnetForm = document.getElementById("aspnetForm&qu ...

  4. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点

    Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...

  5. SQL常用命令浅析

    表操作备注:操作之前使用“use <数据库名>”应连接某个数据库.建表命令:create table <表名> (<字段名 1> <类型 1> [,.. ...

  6. checking it the current os is a 32bit or 64bit version 检查操作系统是32位还是64位

    ) { Console.WriteLine("32bit os"); } ) { Console.WriteLine("64bit os"); }

  7. 瑞昱Realtek(Realtek HD Audio Driver)音频声卡驱动R2.49 for Win7_Vista

    不管是在高端系列主板上,还是在低端系列主板上,我们都能看到Realtek瑞昱的身影,Realtek HD Audio Driver能够支持所有的Realtek HD Audio音频驱动.Realtek ...

  8. js实现方法的链式调用

    假如这里有三个方法:person.unmerried();person.process();person.married();在jQuery中通常的写法是:person.unmerried().pro ...

  9. gentoo

    http://www.aboutyun.com/thread-8522-1-1.html        .java.io.IOException: Connection reset by peer c ...

  10. Android版:验证手机号码的正则表达式

    http://blog.csdn.net/dai_zhenliang/article/details/8186249 /** * 验证手机格式 */ public static boolean isM ...