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. 为linux添加一块新硬盘并分区

    一---如何增加一块硬盘1:虚拟机添加硬盘2:分区3:格式化4:挂载5:设置可以自动挂载 1---设置里面 2---分区命令 fdisk /dev/sdb开始分区m显示命令列表p显示磁盘分区 同fdi ...

  2. Js中函数式编程的理解

    函数式编程的理解 函数式编程是一种编程范式,可以理解为是利用函数把运算过程封装起来,通过组合各种函数来计算结果.函数式编程与命令式编程最大的不同其实在于,函数式编程关心数据的映射,命令式编程关心解决问 ...

  3. redis之集群二:哨兵

    回顾 上一篇介绍了Redis的主从集群模式,这个集群模式配置很简单,只需要在Slave的节点上进行配置,Master主节点的配置不需要做任何更改.但是,我们发现这种集群模式当主节点宕机,主从无法自动切 ...

  4. 【Linux】fstab中 每个字段代表的含义

      默认情况下,fstab中已经有了当前的分区配置,内容可能类似: # <file system> <mount point> <type> <options ...

  5. leetcode 321. 拼接最大数(单调栈,分治,贪心)

    题目链接 https://leetcode-cn.com/problems/create-maximum-number/ 思路: 心都写碎了.... 也许就是不适合吧.... 你是个好人... cla ...

  6. 鸿蒙的fetch请求加载聚合数据的前期准备工作-手动配置网络权限

    目录: 1.双击打开"config.json"文件 2.找到配置网络访问权限位置1 3.配置内容1 4.默认访问内容是空的 5.添加配置内容2 6.复制需要配置的网络二级URL 7 ...

  7. 使用modify修改内表

    modify修改内表,有这样一种方式,MODIFY TABLE itab FROM wa [TRANSPORTING ..]. 然后这里的内表itab是有条件的,这个itab必须要有table key ...

  8. ABAP 面试问题和答案

    What is an ABAP data dictionary?- ABAP 4 data dictionary describes the logical structures of the obj ...

  9. JS实现计算器,带三角函数,根号

    极简主义网页计算器. 实现了按键特效,可响应键盘按键,实时显示计算结果. 可切换模式,拓展高级功能,包括根号.三角函数.括号等. 效果如下: 代码如下: html: <!DOCTYPE html ...

  10. TSP旅行商问题

    求解的问题,burma.tsp里面的内容 1 16.47 96.10 2 16.47 94.44 3 20.09 92.54 4 22.39 93.37 5 25.23 97.24 6 22.00 9 ...