zoukankan      html  css  js  c++  java
  • 字符串处理

    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).

    Example

    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<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    const int maxn=105;
    char s[maxn],t[maxn],p[maxn];
    
    int Find(char *a,char *b){
        int alen=strlen(a);
        int blen=strlen(b);
        int cnt=0;
        for(int i=0;i<blen;i++){
            if(b[i]==a[cnt]){
                cnt++;
            }
        }
        if(cnt==alen){
            return 1;
        }else{
            return 0;
        }
    }
    
    int Insert(char *a,char *b,char *c){
        int alen=strlen(a);
        int blen=strlen(b);
        int clen=strlen(c);
        int ans=0,cnt=0;
        int book[maxn];
        memset(book,-1,sizeof(book));
        for(int i=0;i<clen;i++){
            if(a[cnt]==c[i]){
                cnt++;
                ans++;
            }else{
                for(int j=0;j<blen;j++){
                    if(c[i]==b[j]&&book[j]!=1){
                        ans++;
                        book[j]=1;
                        break;
                    }
                }
            }
        }
        if(ans==clen){
            return 1;
        }else{
            return 0;
        }
    }
    
    int main(){
        int Case;
        scanf("%d",&Case);
        while(Case--){
            scanf("%s%s%s",s,t,p);
            int slen=strlen(s);
            int tlen=strlen(t);
            if(slen>tlen){
                printf("NO
    ");
            }else{
                if(Find(s,t)&&Insert(s,p,t)){
                    printf("YES
    ");
                }else{
                    printf("NO
    ");
                }
            }
        }
        return 0;
    } 
  • 相关阅读:
    WP7开发学习(4):Style样式的四种使用
    如何:查找由 DataTemplate 生成的元素
    wp7——sqlite数据库操作
    SQL Server Reporting Services(简称SSRS)
    WP7入门 (二)主题、样式与模版
    为Pivot不同的PivotItem定制ApplicationBar
    Binding数据绑定
    (仿QQ聊天消息列表加载)wp7 listbox 列表项逐一加载的一种实现方式,以及加入渐显动画
    WPF中Binding的技巧
    sql server 里的 over
  • 原文地址:https://www.cnblogs.com/qqshiacm/p/11616100.html
Copyright © 2011-2022 走看看