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");
    }
}

 

转载于:https://www.cnblogs.com/thmyl/p/8184865.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值