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

题意:给你两个字符串s1,s2,你可以在s1中选择任意一个字符,并且在后面添加任意与之不同的字符在后面,如果添加若干或者不添加能使s1变成s2,就输出Yes,否则输出No.

思路:只要满足两个条件就输出Yes:1.两个字符串首字母必须相等且第一个字符串中首字母连续的个数必须小于等于第二个字符。2.对于任意一个字符c,它在第一个字符串中的个数要小于等于第二个字符串的。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 100050
char s1[maxn],s2[maxn];
int num1[27],num2[27];
int main()
{
int n,m,i,j,T,len1,len2,flag1,sum1,sum2,flag2,flag;
char c1,c2;
scanf("%d",&T);
while(T--)
{
scanf("%s%s",s1,s2);
if(strcmp(s1,s2)==0){
printf("Yes\n");continue;
}
len1=strlen(s1);
len2=strlen(s2);
c1=s1[0];c2=s2[0];
if(c1!=c2){
printf("No\n");continue;
}
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
sum1=sum2=0;flag1=flag2=1;
for(i=1;i<len1;i++){
if(flag1 && s1[i]==s1[0])sum1++;
else flag1=0;
num1[s1[i]-'a'+1]++;
}
for(i=1;i<len2;i++){
if(flag2 && s2[i]==s2[0])sum2++;
else flag2=0;
num2[s2[i]-'a'+1]++;
}
if(sum1<sum2){
printf("No\n");continue;
}
flag=1;
for(i=1;i<=26;i++){
if(num1[i]>num2[i]){
flag=0;break;
}
}
if(flag)printf("Yes\n");
else printf("No\n");
}
return 0;
}

hdu5414 CRB and String的更多相关文章

  1. HDU-5414 CRB and String

    http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不 ...

  2. CRB and String

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

  3. 【HDOJ 1009】 CRB and String

    [HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...

  4. HDOJ 5414 CRB and String 模拟

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

  5. HDU_5414 CRB and String 【字符串】

    一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...

  6. hdu5414(2015多校10)--CRB and String(字符串匹配)

    题目链接:pid=5414">点击打开链接 题目大意:有A.B两个字符串.如今有一种操作能够在A的随意一个字符x后面添加一个字符y(x.=y).问能不能将A变为B. 首先假设A能够变成 ...

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

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

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

    题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...

  9. 多校第十场1009 CRB and String题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给你两个字符串s和t,你能够在字符串s中随意选一个字符c,在该字符c后插入一个字符d(d! ...

随机推荐

  1. MySQL的索引优化分析(一)

    一.SQL分析 性能下降.SQL慢.执行时间长.等待时间长 查询语句写的差 索引失效关联查询太多join(设计缺陷) 单值索引:在user表中给name属性创建索引,create index idx_ ...

  2. Azure Terraform(五)利用Azure DevOps 实现自动化部署基础资源

    一,引言 上一篇我们结合学习 Azure Traffic Manger 的内容,做了一个负载均衡的基础设施架构.通过 Terraform 部署执行计划,将整个 Azure Traffic Manage ...

  3. 【Linux】awk想打印制定列以后的所有列

    今天偶然研究awk,有一个文件,文件内容是全篇的1 2 3 4 5 6 7 8 9 0 现在想打印除了第一列意外的所有列 文件内容: [root@localhost ~]# cat test.txt ...

  4. ORA-00245 control file backup operation failed 分析和解决

    一.问题说明 操作系统: RedHat 5.8 数据库: 11.2.0.3 2节点RAC. 使用RMAN 备份的时候,报如下错误: ORA-00245: control file backup fai ...

  5. 【Linux】fdisk -l发现有加号"+"

    今天分区不够了,打算扩下分区,想起当时创建机器的时候还有大约80多个G没有用,今天打算重新利用上 就用了fdisk /dev/sda 创建了两个分区,但是发现分区下面有加号,感到而别的困惑 最后在很多 ...

  6. 剑指 Offer 27. 二叉树的镜像

    同LeetCode226翻转二叉树 1 class Solution { 2 public: 3 TreeNode* mirrorTree(TreeNode* root) { 4 if(root == ...

  7. JCO RFC destination

    一:登陆PI的GUI,进入事物SM59,创建T类型RFC destinations如下: AI_RUNTIME_JCOSERVER  :used for the mapping runtime, va ...

  8. 09--Docker 安装tomcat9

    1.在hub.docker.com中获取tomcat拉取地址 docker pull tomcat:9.0.41-jdk8-corretto 2.查看Dockerfile 中WORKDIR 为/use ...

  9. 在HTML中改变input标签中的内容

    在HTML中改变input标签的内容 1.使用js自带的方法: document.getElementById('roadName').value='武汉路';//通过标签选择器来选择标签,然后设置值 ...

  10. 记录list.remove()和list.pop()

    list.remove(obj):这个是移除列表中某个值的第一个匹配项 list.pop(index):这个是移除列表中下标为index的元素 当元素全是数字或者有数字时注意区分.