HDU 5414 CRB and String(字符串处理)——多校练习10

来源:互联网 发布:企业生产软件 编辑:程序博客网 时间:2024/05/08 18:57

CRB and String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


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 (dc) 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
4abcatcatsdodoappleaapple
 

Sample Output
NoYesYesNo
 

Author
KUT(DPRK)
 

Source
2015 Multi-University Training Contest 10
 
/*********************************************************************/

题意:给你两个字符串s和t,你可以在字符串s中任意选一个字符c,在该字符c后插入一个字符d(d!=c),问经过多次此操作,能否将字符串s转化成字符串t

放上出题人的解题报告


解题思路:首先拿到这样的题目,我们当然是来找找怎么样的s是能够转化成t的,经过举例,我们可以得到如下两个条件

①字符串s是字符串t的子串,即t是包含s的字符串,比如说s=cat  t=cbadt

②若字符串t前k个字符都相同,那么字符串s的前k个字符也必须相同,比如说 s=aabcd  t=aabcde 是可以转化的,而s=aabcd  t=aaabcd 则是不可以转化的,因为我们没有办法在a后面插入a,因为题目要求插入的字符d!=选择的字符c

只要符合上述两个条件的字符串s,都可以转化成字符串t

这个时候有些人会疑问,难道后面有不等长的字符串就可以转化了?比如说 s=apple  t=appple

虽说我们没办法在p字符后面插入p,但是我们可以在a字符后面插入p,这样我们就可以做到s转化成t了

放上几组样例以供参考

Input

b
ab

Output

No


Input
apple
appapple

Output

Yes

Input
apple
appple

Output

Yes

Input
aa
aaa

Output

No

说了这么多,剩下的靠你们理解咯,老样子,不理解的欢迎提出来

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 100005;const int inf = 1000000000;const int mod = 1000000007;char s[N],t[N];int main(){    int T,i,j,k;    scanf("%d",&T);    while(T--)    {        scanf("%s%s",s,t);        for(k=i=j=0;t[i]!='\0';i++)        {            if(!k&&t[i]==t[0]&&s[i]!=t[0])//t的前k个字符相等,那么s的前k个字符也必须相等                break;            if(t[i]!=t[0])                k=1;            if(s[j]!='\0'&&t[i]==s[j])//s是t的子串                j++;        }        if(t[i]=='\0'&&s[j]=='\0')            puts("Yes");        else            puts("No");    }    return 0;}
菜鸟成长记


0 0
原创粉丝点击