2015多校联合第十场 hdu5414CRB and String字符串思维题

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




cat 
cats 
do 
do 
apple 
aapple

Sample Output

No 
Yes 
Yes 

No

据说啊 只需要保证两个条件:

1:s是t的字串 
2:对于t前k个字符如果是相同的s的前k个字符也必须是相同的

啊啊啊啊啊啊 现在才发现 居然一直看错题了!!选出来的c不删掉 只是在后面加一个d(d!=c)

#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-10
using 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;
}


你可能感兴趣的:(String,HDU,多校)