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查找软件的安装路径

    软件安装的路径可能不止一个,可以使用whereis命令查看软件安装的所有路径,以mysql为例: whereis mysql 该命令会返回软件的所有安装路径: mysql: /usr/bin/mysq ...

  2. WPF 列表控件中的子控件上下文绑定

    <DataGrid Grid.ColumnSpan=" Height="Auto" SelectedItem="{Binding Path=SelectP ...

  3. 前端资源多个产品整站一键打包&包版本管理(四)—— js&css文件文件打包并生成哈希后缀,自动写入路径、解决资源缓存问题。

    问题: 当我们版本更新的时候,我们都要清理缓存的js跟css,如何使得在网页中不需要手动清理呢? 答案: 生成带有哈希后缀的js跟css文件 1.文件路径 路径中的conf.js 是用于放置全局打包的 ...

  4. MySQL基础学习之视图

    创建新的视图 CREATE VIEW 视图名  AS SELECT  属性,属性1,属性2  FROM 表名 创建新的视图并指定数据名 CREATE VIEW 视图名(新属性,新属性1,新属性2)   ...

  5. Catch Application Exceptions in a Windows Forms Application

    You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. Thi ...

  6. node.js 1Million concurrent connections!

    https://github.com/ashtuchkin/node-millenium http://blog.caustik.com/2012/08/19/node-js-w1m-concurre ...

  7. NetWorker常用术语

    术语 描述 active group 每24小时至少计划备份一次的备份组. Advanced File Type Device (AFTD) 为大容量磁盘设备和并发操作设计的磁盘备份设备配置选项. A ...

  8. centos 下查找软件安装在哪里的命令

    linux centos 下查找软件所安装的目录在哪里 1. 如果是rpm安装的可以:rpm -ql linux(1)package-name 具体你可以man rpm 2. 可以在根目录上直接fin ...

  9. Java中的编码

    package coreJava; import javax.swing.plaf.synth.SynthSpinnerUI; public class EncodeDemo { public sta ...

  10. bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消

    4004: [JLOI2015]装备购买 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 337  Solved: 139[Submit][Status ...