• CodeForces


    You are given three strings ss, tt and pp consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

    During each operation you choose any character from pp, erase it from pp and insert it into string ss (you may insert this character anywhere you want: in the beginning of ss, in the end or between any two consecutive characters).

    For example, if pp is aba, and ss is de, then the following outcomes are possible (the character we erase from pp and insert into ss is highlighted):

    • aba → ba, de → ade;
    • aba → ba, de → dae;
    • aba → ba, de → dea;
    • ab→ aa, de → bde;
    • ab→ aa, de → dbe;
    • ab→ aa, de → deb;
    • ab→ ab, de → ade;
    • ab→ ab, de → dae;
    • ab→ ab, de → dea;

    Your goal is to perform several (maybe zero) operations so that ss becomes equal to tt. Please determine whether it is possible.

    Note that you have to answer qq independent queries.

    Input

    The first line contains one integer qq (1q1001≤q≤100) — the number of queries. Each query is represented by three consecutive lines.

    The first line of each query contains the string ss (1|s|1001≤|s|≤100) consisting of lowercase Latin letters.

    The second line of each query contains the string tt (1|t|1001≤|t|≤100) consisting of lowercase Latin letters.

    The third line of each query contains the string pp (1|p|1001≤|p|≤100) consisting of lowercase Latin letters.

    Output

    For each query print YES if it is possible to make ss equal to tt, and NO otherwise.

    You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

    Input
    4
    ab
    acxb
    cax
    a
    aaaa
    aaabbcc
    a
    aaaa
    aabbcc
    ab
    baaa
    aaaaa
    
     
    Output
    YES
    YES
    NO
    NO
    

    Note

    In the first test case there is the following sequence of operation:

    1. s=s= ab, t=t= acxb, p=p= cax;
    2. s=s= acb, t=t= acxb, p=p= ax;
    3. s=s= acxb, t=t= acxb, p=p= a.

    In the second test case there is the following sequence of operation:

    1. s=s= a, t=t= aaaa, p=p= aaabbcc;
    2. s=s= aa, t=t= aaaa, p=p= aabbcc;
    3. s=s= aaa, t=t= aaaa, p=p= abbcc;
    4. s=s= aaaa, t=t= aaaa, p=p= bbcc.

    这里贴一个别人的代码

    #include<bits/stdc++.h>
    using namespace std;
    #define forn(i,n)  for(int i=0;i<n;i++)
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    const int maxn=1e5+5;  
    const int INF=0x3f3f3f3f;
    
    
    int a[maxn],sum[maxn],c[maxn];
    int n,q;
    string s,t,p;
    int solve(){
        int i=0,j=0;
        int lens=s.size(),lent=t.size();
        while(i<lens && j<lent){
            if(s[i]==t[j])
                i++;
            else
                c[t[j]-'a']++;  
            j++;
        }
        if(i<lens)    
        {
            return 0;
        } 
        if(j<lent){
            for(;j<lent;j++){        
                c[t[j]-'a']++;
            }
        }    
        for(char o:p){ 
            c[o-'a']--;
        }
        for(int i=0;i<26;i++){
            if(c[i]>0)
                return 0;
        }
        return 1;
    } 
    int main(){
        
        
        cin>>q;
        while(q--){
            cin>>s>>t>>p;   
            memset(c,0,sizeof c);
            cout<<(solve()?"YES":"NO")<<endl;
        }
        
        return 0;
    }

    2019-7-24

    发现了昨天双指针发的错误, 没有判断第一个串有没有读尽,

    哎,是我愚蠢了

    #include<bits/stdc++.h>
    using namespace std;
    int ss[26], tt[26], need[26], have[26];
    #define ZERO(a) memset(a, 0, sizeof(a))
    
    int main()
    {
        int T;
        cin >> T;
        while(T--)
        {
            string s,t,p;
            cin >> s >> t >> p;
    
            ZERO(need); ZERO(have);
    
            for(int i = 0; i < p.size(); i++)
                have[p[i] - 'a']++;
    
            int j = 0;
            int flag = 0;
            for(int i = 0; i < t.size(); i++)
            {
                if(s[j] == t[i] && j < s.size()) j++;
                else
                {
                    if(have[t[i] - 'a'] > 0) --have[t[i] - 'a'];
                    else
                    {
                        flag = 1;
                        break;
                    }
                }
            }
            if(j != s.size()) flag = 1;
            if(flag == 0) puts("YES");
            else puts("NO");
        }
    
    
    }
  • 相关阅读:
    eclipse插件egit安装使用
    github 项目版本控制
    div box container随主体内容自动扩展适应的实现
    持续构建与每日集成
    Xshell连接Linux下Oracle无法回退的解决办法
    Java Data JPA +hibernate 保存或者是查询遇到的坑
    C#控件DropDownList下拉列表默认打开
    window.open居中显示
    CSV文件转JSON
    Vue自定义事件,$on(eventName) 监听事件,$emit(eventName) 触发事件
  • 原文地址:https://www.cnblogs.com/YY666/p/11233438.html
Copyright © 2020-2023  润新知