hdu 5414 CRB and String

CRB and String

 HDU - 5414 

题目大意:给定两个字符串 S 和 T。你每次可以在 S 的某个字符 c 后面添加一个字符 d,且要保证 c != d。问有没有可能把 S 变成 T。1≤|S|≤|T|≤100000。

/*
    首先 S 必须要是 T 的子序列,且 S1 = T1。
    因为字符不同的限制,所以 S 开头连续相同的字符数要不大于 T 开头连续相同的字符数。
    如果满足以上条件,那么一定可以得到 T。
    时间复杂度 O(n)。 
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100010
using namespace std;
int n,m;
char s[maxn],t[maxn];
int main(){
    int T;scanf("%d",&T);
    while(T--){
        scanf("%s%s",s+1,t+1);
        n=strlen(s+1);m=strlen(t+1);
        if(s[1]!=t[1]){puts("No");continue;}
        int i=1,j=1;
        while(i<=n&&j<=m){
            while(j<=m&&s[i]!=t[j])j++;
            if(s[i]==t[j])i++,j++;
        }
        if(s[i-1]!=t[j-1]){puts("No");continue;}
        int n1=1,n2=1;
        for(int i=2;i<=n;i++){
            if(s[i]!=s[i-1])break;
            n1++;
        }
        for(int i=2;i<=m;i++){
            if(t[i]!=t[i-1])break;
            n2++;
        }
        
        if(n1<n2)puts("No");
        else puts("Yes");
    }
}

 

posted @ 2018-01-03 17:35  Echo宝贝儿  阅读(158)  评论(0编辑  收藏  举报