CRB and String
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的更多相关文章
- HDU-5414 CRB and String
http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不 ...
- 【HDOJ 1009】 CRB and String
[HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...
- HDOJ 5414 CRB and String 模拟
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- HDU_5414 CRB and String 【字符串】
一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...
- hdu5414 CRB and String
Problem Description CRB has two strings s and t. In each step, CRB can select arbitrary character c ...
- HDU 5414 CRB and String (2015年多校比赛第10场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...
- HDU 5414 CRB and String (字符串,模拟)
题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...
- 多校第十场1009 CRB and String题解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给你两个字符串s和t,你能够在字符串s中随意选一个字符c,在该字符c后插入一个字符d(d! ...
- 构造 HDOJ 5414 CRB and String
题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...
随机推荐
- 解决xcode6_beta没有代码提示的方法
在beta版本的xcode6中我们会发现代码提示不怎么好使,但是看一些老外的视频,他们的代码提示却又是赶赶的.这是为什么呢?其实解决办法也很简单.就是在项目中不出现中文字符就好了.有的同学说,我没用中 ...
- PostgreSQL index types and index bloating
warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...
- navicat 的查询功能
navicat的查询的位置在: 在编辑器界面写代码,代码完成后点左上角的运行. 代码: create(创建) table(一个表) <xxx>尖括号内的内容必填——我要创建并查询一个名叫 ...
- 转:python webdriver API 之层级定位
在实际的项目测试中,经常会有这样的需求:页面上有很多个属性基本相同的元素 ,现在需要具体定位到其中的一个.由于属性基本相当,所以在定位的时候会有些麻烦,这时候就需要用到层级定位.先定位父元素,然后再通 ...
- IUS通过PLI产生fsdb波形
IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...
- jQuery讲解
在讲解jQuery时,要和JavaScript进行对比的讲解,易于理解 JavaScript部分 <title>jquery讲解使用</title> <script sr ...
- js同步访问后台资源
$.ajax( { type : 'post', url : url, data : data, async : false,//false代表只有在等待ajax执行完毕后才执行window. ...
- Yii2下拉框实现
详细介绍yii2下拉框的实现方法,以商品分类的下拉框为例: 第一种方法:使用Html的activeDropDownList(),该方法的优点是:可以自定义下拉框的样式.具体实现如下: 1.控制器中,获 ...
- C语言初学者代码中的常见错误与瑕疵(2)
问题: 另一种阶乘 大家都知道阶乘这个概念,举个简单的例子:5!=1*2*3*4*5. 现在我们引入一种新的阶乘概念,将原来的每个数相乘变为i不大于n的所有奇数相乘 例如:5!!=1*3*5.现在明白 ...
- 关于undefined reference to `WSASocketA@24'问题的解决
关于 Eclipse 开发C++ Socket ,在开发的过程中 用WinGW 平台编译, 示例server端: #include <winsock2.h> #include <m ...