HDU 5414 CRB and String(水~)
来源:互联网 发布:mac游戏推荐单机游戏 编辑:程序博客网 时间:2024/06/08 06:02
Description
给出两个字符串,可以对第一个字符串的任意一个字符后面插入任一个不同于该字符的字符,问是否可以经过若干次操作把第一个串变成第二个串
Input
第一行一整数T表示用例组数,每组用例输入两个字符串s和t(1<=T<=1e5,1<=|s|<=|t|<=1e5,输入文件不超过5MB)
Output
对于每组用例,如果s可以经过一些操作变成t则输出Yes,否则输出No
Sample Input
Sample Input
4
a
b
cat
cats
do
do
apple
aapple
Sample Output
No
Yes
Yes
No
Solution
可以看出如果s可以变成t那么s首先应该可以“嵌入”到t中,并且由于每次插入只能在某个字符后面插入一个不同于该字符的字符,所以如果s的第一个字符不等于t的第一个字符则无解,如果s前端由相同字母构成的连续部分的长度小于t前端由相同字母构成的连续部分的长度也无解,如果这两个条件均满足,则去掉前端连续相同的部分,去判断s的剩余部分是否可以嵌入到t中,可以就Yes,否则No
Code
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#include<ctime>#include<map>#include<set>using namespace std;#define maxn 111111char s[maxn],t[maxn];bool check(int len1,int len2){ if(s[0]!=t[0])return 0; if(len1==len2)return strcmp(s,t)==0; char c=s[0]; int i=0,j=0; while(i<len1&&s[i]==c)i++; while(j<len2&&t[j]==c)j++; if(j>i)return 0; j++,i=j; while(i<len1) { while(j<len2&&t[j]!=s[i])j++; if(j==len2)break; i++; } return 1;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%s%s",s,t); int len1=strlen(s),len2=strlen(t); printf("%s\n",check(len1,len2)?"Yes":"No"); } return 0;}
阅读全文
0 0
- HDU 5414 CRB and String(水~)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String(贪心)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String
- hdu 5414 CRB and String
- HDU 5414 CRB and string
- hdu 5414 CRB and String
- HDU 5414CRB and String
- hdu 5414 CRB and String(想法题)
- [HDU 5414] CRB and String (构造+脑洞)
- 贪心,模拟,构造(HDU 5414,CRB and String)
- hdu 5414 CRB and String (贪心)
- [思路题] hdu 5414 CRB and String
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String||QDUOJ GZS and String
- HDU 5414(2015多校10)-CRB and String(字符串处理)
- 计算机端口详解
- mysql中的时间类型
- qt入门教程收集
- 转 jquery选择器空格与大于号、加号与波浪号的区别
- Java-web分页操作(jsp+servlet+javaBean)
- HDU 5414 CRB and String(水~)
- 字符、字节的概念及其区别
- VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- select * from book where 1=1
- json数据转换异常:net.sf.json.JSONException: Java.lang.reflect.InvocationTargetException
- Java中的final共有三种用法(转)
- 计算机系统要素:第二章 布尔运算
- 设备兼容思考——RWD:响应式WEB
- json对象和json字符串区别