GZS and String

https://qduoj.com/problem/6?tdsourcetag=s_pctim_aiomsg

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

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

思路:

1.如果t串前j个字符相同,那么s串前j个字符也必须相同(因为插入的字符d!=c) 

例:abc

        aabc

        No

2.s串必须是t串的子序列

满足这两个条件的就Yes

aacc

aacccc

Yes

(虽然c后不能插入c但是可以在a后面插入)

#include<cstdio>
#include<cstring>
using namespace std;
char s[100005],t[100005];
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		scanf("%s%s",s,t);
		int ls=strlen(s),lt=strlen(t);
		int i,j;
		bool flag=true;
		for(j=1; j<lt; j++) {     //判断t串前面有多少个相同的字母 
			if(t[j]!=t[0]) break;
		}
		for(i=0; i<j; i++) {     //判断s串前j个字母是否与t串一样 
			if(s[i]!=t[0]) {     //如果不一样肯定No(无法插入) 
				flag=false;       
				break;
			}
		}
		if(flag) {               //再判断s串是不是t串的子序列 
			for(i=0,j=0; j<lt;) {  
				if(s[i]==t[j]) {
					i++;
					j++;
				} else
					j++;
			}
			if(i<ls) {           //如果不是就No 
				flag=false;
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}