Description

GZS has two strings s and t.

In each step, GZS can select arbitrary character c of s and insert any character d (d ≠ c) just after it.

GZS 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 ≤ 10^5 1 ≤ |s| ≤ |t| ≤ 10^5 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 GZS can convert s to t, otherwise output "No".

Sample Input 1

4
a
b
cat
cats
do
do
apple
aapple

Sample Output 1

No
Yes
Yes
No

题意:一开始读错题了,以为只能插一个,是可以插很多个,每个要满足插入的规则就可以了

思路:看长串中是否包含短串的所有字符,如果都有再判断前面有多少个相同的,如果短串的大于等于长串的,并且首字符一定要相同,就可以,否则就不可以,否则就说明插了重的

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define MAX  100005
using namespace std;char s1[MAX],s2[MAX];
int main() {int T;cin>>T;for(int t=0; t<T; t++) {scanf("%s",s1);scanf("%s",s2);int i;i=0;int len1=strlen(s1);int len2=strlen(s2);for(int j=0; i<len1&&j<len2; j++) {if(s1[i]==s2[j]) {i++;}}if(i!=len1) {printf("No\n");} else {int sum1=0,sum2=0;for(int j=1; j<len1; j++) {if(s1[j]==s1[j-1]) {sum1++;} else {break;}}for(int j=1; j<len2; j++) {if(s2[j]==s2[j-1]) {sum2++;} else {break;}}if(s1[0]==s2[0]&&sum1>=sum2) {printf("Yes\n");} else {printf("No\n");}}}return 0;
}

也可以参考大佬的思路及代码

链接:

https://blog.csdn.net/qq_42936517/article/details/85886959

转载于:https://www.cnblogs.com/Staceyacm/p/10781859.html

QDU-GZS and String相关推荐

  1. Java知识——精华总结

    Java知识--精华总结 一.java概述与基础知识 1.何为编程? 编程就是让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程. 为了使计算机能够理解人的意图,人类就必须 ...

  2. 利用java爬虫QDU教务课表

    前言 前几天有个做校园app的同学让我研究一下怎么爬个人的教务课表,就像课程格子那样导入课程.这里我放出初步的获取课表页html代码的程序,有需要的同学可以拿去用,By the way 听说有个叫Js ...

  3. mybatis查询报错:com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from string

    mybatis查询报错: com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from strin ...

  4. Go 学习笔记(60)— Go 第三方库之 go-redis(初始化 redis、操作 string、操作 list、操作 set、操作 hset)

    1. 第三方库 go-redis 因为 Go 标准库中是没提供 redis 的库,所以我们选择用 go-redis 这个第三方库.源码地址为 https://github.com/go-redis/r ...

  5. Redis 笔记(03)— string类型(设置key、获取key、设置过期时间、批量设置获取key、对key进行加减、对key值进行追加、获取value子串)

    字符串 string 是 Redis 最简单的数据结构.Redis 所有的数据结构都是以唯一的 key 字符串作为名称,然后通过这个唯一 key 值来获取相应的 value 数据.不同类型的数据结构的 ...

  6. python中的raw string的使用

    背景 我们经常需要使用raw string,在应用过程中,比如要使字符串中带一些转义字符或者其他的一些符号,我们就需要保持我们的字符成为raw string. 实例 输入 s = 'fadfafa\n ...

  7. Java中如何实现Date与String之间的数据类型转换

    String 数据类型转换成 Date String inputDate = "2021-04-11";Date outputDate = null;SimpleDateForma ...

  8. C++ string字符串的比较是否相等

    C++ string字符串的比较是否相等 可以使用compare 也可以使用"==" 1 使用比较运算符 == #include <iostream> #include ...

  9. python string 转bytes 以及bytes 转string

    string转 bytes 使用 encode str_a = "Python" str_bytes = str_a.encode() # encode默认编码方式是utf-8 所 ...

  10. TypeError: string argument without an encoding

    这个错误是把string 类型转byte类型的时候出现的问题 下面就会报错 print(bytes(str_a)) 修改为如下就好了 print(bytes(str_a.encode())) 或者就不 ...

最新文章

  1. 生成公钥链接github
  2. 日志处理两大生态Splunk和ELK深度对比
  3. [转] ROS cmake_modules
  4. 看这玩意复习你还会挂科?《软件工程2篇》
  5. NPER用计算机怎么算,计算机财务管理第三章详解.doc
  6. AndroidStudio_安卓原生开发_搭建AdnroidStudio环境并配置SDK---Android原生开发工作笔记136
  7. 尺取法---poj3601
  8. STS下载教程(include官网无法下载解决方案)
  9. 我的Java和Android之路------菜冬瓜
  10. aix6 AIO 动态调整
  11. write函数的详解与read函数的详解
  12. 微信连wifi正式全量对外开放申请 升级智能服务
  13. 产品分析报告—年轻人的体育社区—虎扑
  14. 计算机人事管理参考文献,计算机人事管理系统毕业论文设计.doc
  15. Discourse 论坛激活邮件问题
  16. 在橙黄色网站设计中寻找灵感
  17. 除了SVN,还可以使用的文档管理工具--TFS; 使用VS2010连接TFS的使用说明和简单操作手册
  18. 北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(4)
  19. Dubbo系列5:Dubbo协议
  20. 【VIO】第2讲 基于优化的IMU

热门文章

  1. 法语语言考试C1,法语考试大比拼:专八与Dalf C1,哪个更难?
  2. java f反射_java反射机制
  3. java 如何循环执行一个对象_一个Java对象到底有多大?
  4. 【若依(ruoyi)】Bootstrap-Table表格排序
  5. 淘宝NPM镜像、cnmp
  6. android手机连接无线路由器上网设置,能连接WIFI但无法上网?教你如何为手机分配固定IP图文教程...
  7. 特异性matlab,基于灰色理论计算位置特异性矩阵
  8. Centos7设置Tomat开机自启
  9. 微型计算机引脚,微型计算机硬件基础8086引脚.doc
  10. mysql课程设计案例_JAVA中MySQL建立连接