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. Linux FTP服务安装和远程登录失败

    问题:本机VPlayer安装pure-ftpd  ftp服务,通过flashfxp从windows连接出现以下错误: [左] 正在连接到 vmare -> IP=192.168.174.133 ...

  2. Eat that Frog

    Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...

  3. frameset,frame应用,常用于后台

    <!DOCTYPE HTML><html><head><title>lin3615</title></head><fram ...

  4. AngularJS(2)-Scope作用域和控制器

    $scope: 根作用域 所有的应用都有一个 $rootScope,它可以作用在 ng-app 指令包含的所有 HTML 元素中. $rootScope 可作用于整个应用中.是各个 controlle ...

  5. 摘自淘宝的js地区组件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. python AES 加密与解密

    #用aes加密,再用base64 encode def aes_encrypt(data): from Crypto.Cipher import AES import base64 key=setti ...

  7. 2014年度辛星css教程夏季版第二节

    第一节我们简介了一下CSS的工作流程,我相信读者会有一个大体的认识,那么接下来我们将会深入的研究一下CSS的细节问题,这些问题的涉及将会使我们的工作更加完善. *************注释***** ...

  8. MVC-Html.Label(TextBox、TextArea、RadioButton、CheckBox)

    红色表示可选参数. @Html.Label("name", "value", new { @class = "class", @style ...

  9. mysql查询结果中文显示成了问号

    在mysql的配置文件my.ini中的[mysqld]项中加这两句 character-set-server = utf8 collation-server = utf8_general_ci 在任务 ...

  10. css3 旋转出现动画

    @-moz-keyframes daf{ 0% { -moz-transform: rotate(-360deg) scale(0.2); -webkit-transform: rotate(-360 ...