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 (
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
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
#include
#include
#include
#include
#include
#include
菜鸟成长记