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] 一定是 ...
随机推荐
- 更改Mysql数据库中的数据出现乱码问题
数据库服务器环境:windows 7 专业版 Mysql版本:5.5.36 出现问题:搭完工程之后,在做保存和插入操作时,涉及的数据在数据库中为变为乱码. 解决方案: MySQL数据库 ...
- linux:档案与目录管理
几个常见的目录处理命令: cd(change directory):变更目录 pwd(print working directory):显示当前目录[目录为连结档,则只显示连结档的路径]([-P]不以 ...
- tableview在第一次显示时会自动relodata
tableview在第一次显示时会自动加载数据
- 避免硬编码你的PostgreSQL数据库密码
一个密码文件包含了我们需要连接的五个字段,所以我们可以使用文件权限来使密码更安全. host:port:dbname:user:password such as myhost:5432:postgre ...
- Lintcode: Partition Array
Given an array "nums" of integers and an int "k", Partition the array (i.e move ...
- [转]Apache Maven 入门篇 ( 上 )
原文地址:Apache Maven 入门篇 ( 上 ) 作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这 ...
- Appium的理念
1.Appium的架构:C/S模式 Appium的核心是暴漏REST API的WebServer,appium接收来自客户端的连接请求,监听由客户端发起的命令,在移动设备上执行这些命令,这些命令的执行 ...
- Spring中Bean的配置:基于XML文件的方式
Bean的配置一共有两种方式:一种是基于XML文件的方式,另一种是基于注解的方式.本文主要介绍基于XML文件的方式 <bean id="helloWorld" class=& ...
- Hbase HRegionServer启动后自动关闭
突然发现HBASE无法使用了. 然后看到在分布式的情况下,节点上的HRegionServer启动后自动关闭. 同步时间就能解决这个问题. 网上同步时间 1. 安装ntpdate工具 sudo apt ...
- EBS多OU和多帐套客户化总结
(一) 多OU总结 . Form多OU实现 ) 创建一个Table,以CUX_AP_CHECK_HEADER_ALL为例 ) 创建Table的两个Synonym(一个不含_ALL,一个以_ALL结尾) ...