Codeforces 1194C. From S To T

Portal

First greed, $ S $ can and should try to match the $ T $ match, just let the rest of the $ P $ to fill

In the case of the $ S $ match all, take a look at $ P $ if there is enough character to

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int N=233;
int Q,n,m,K,cnt[N],cntt[N];
char s[N],t[N],p[N];
bool vis[N];
int main()
{
    Q=read();
    while(Q--)
    {
        scanf("%s",s+1); scanf("%s",t+1); scanf("%s",p+1);
        int n=strlen(s+1),m=strlen(t+1),K=strlen(p+1);
        if(n>m) { printf("NO\n"); continue; }
        memset(vis,0,sizeof(vis));
        for(int i=0;i<30;i++) cnt[i]=cntt[i]=0;
        for(int i=1;i<=K;i++) cnt[p[i]-'a']++;
        int l=0,p=1;
        for(int i=1;i<=m;i++)
        {
            if(t[i]!=s[p]) continue;
            vis[i]=1; p++; if(p>n) break;
        }
        if(p<=n) { printf("NO\n"); continue; }
        bool GG=0;
        for(int i=1;i<=m;i++)
            if(!vis[i])
            {
                cntt[t[i]-'a']++;
                if(cntt[t[i]-'a']>cnt[t[i]-'a']) GG=1;
            }
        if(GG) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/LLTYYC/p/11597764.html