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. Centos 6 下安装 OSSEC-2.8.1 (一)

    ossec -2.8.1 安装: ## 1 ) 安装依赖包: RedHat / Centos / Fedora / Amazon Linux yum install -y pcre mysql mys ...

  2. SpringSecurity应用篇

    前面吹水原理吹了一篇幅了,现在讲解下应用篇幅,前面说过,如果要用SpringSecurity的话要先导入一个包 <dependency> <groupId>org.spring ...

  3. Redis 实战 —— 01. Redis 数据结构简介

    一些数据库和缓存服务器的特性和功能 P4 名称 类型 数据存储选项 查询类型 附加功能 Redis 使用内存存储(in-memory)的非关系数据库 字符串.列表.哈希表.集合.有序集合 每种数据类型 ...

  4. 3A的限流芯片PW1503

    PW1503是超低RDS(ON)开关,具有可编程的电流限制,以保护电源于过电流和短路情况.它具有超温保护以及反向闭锁功能. PW1503采用薄型(1毫米)5针薄型SOT封装,提供可调版本. 特征    ...

  5. Linux的环境变量配置在/etc/profile或/etc/profile.d/*.sh文件中的区别是什么?

    @ 目录 login shell non-login shell 它们的区别 Linux的环境变量可在多个文件中配置,如/etc/profile,/etc/profile.d/*.sh,~/.bash ...

  6. IEEE Standard 754 for Binary Floating-Point Arithmetic

    IEEE 754-2008 - IEEE Standard for Floating-Point Arithmetic https://standards.ieee.org/standard/754- ...

  7. Monkey patching

    "A monkey patch is a way to extend or modify the run-time code of dynamic languages without alt ...

  8. 监听套接字描述字 已连接套接字描述字 和打电话的情形非常不一样的地方 完成了 TCP 三次握手,操作系统内核就为这个客户生成一个已连接套接字

    1. accept: 电话铃响起了-- 当客户端的连接请求到达时,服务器端应答成功,连接建立,这个时候操作系统内核需要把这个事件通知到应用程序,并让应用程序感知到这个连接.这个过程,就好比电信运营商完 ...

  9. list中map 的value值时间排序

    public static void main(String[] args) { String sys=DateUtil.getTime().substring(0,5); System.out.pr ...

  10. 使用eventfd创建一个用于事件通知的文件描述符

    https://www.jianshu.com/p/57cc1d7d354f nat穿透代码c++