C. From S To T

博客提到昨天做Codeforces题目时,C题比B题简单,并给出了C题的链接http://codeforces.com/contest/1194/problem/C 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述在这里插入图片描述
//昨天做的时候C题,比B题要简单
http://codeforces.com/contest/1194/problem/C

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
    char str1[105],str2[105],str3[105];
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        map<char,int>h;
        map<char,int>hou;
     scanf("%s%s%s",str1,str2,str3);
     int len1=strlen(str1);
    int len2=strlen(str2);
    for(int i=0;i<len1;i++)
    {
      h[str1[i]]++;
    }
    for(int i=0;i<len2;i++)
    {
      hou[str2[i]]++;
    }
    int flag=0;
    for(int i=0;i<26;i++)
    {
        if(h['a'+i]>hou['a'+i])
        {
            flag=1;
            break;
        }
        else
        {
            hou['a'+i]=hou['a'+i]-h['a'+i];
        }
    }
    if(flag==1)//如果s串中有比t串中多的,一定不行
    {
        printf("NO\n");
    }
    else
    {
        int k1=0;
        for(int i=0;i<len2;i++)
        {
            if(str2[i]==str1[k1])
            k1++;
            if(k1==len1)
            break;
        }
        if(k1!=len1)
        {
            printf("NO\n");//s串中的顺序一定跟t串一样
            continue;
        }
 
        int len3=strlen(str3);
         map<char,int>k;
        for(int i=0;i<len3;i++)
        {
          k[str3[i]]++;
        }
        for(int i=0;i<26;i++)
        {
            if(k['a'+i]<hou['a'+i])//看看第三个串能不能补上第一个
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
        printf("NO\n");
        else
        printf("YES\n");
 
    }
    }
 
 
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值