Simple String

Welcome,this is the 2015 3th Multiple Universities Programming Contest ,Changsha ,Hunan Province. In order to let you feel fun, ACgege will give you a simple problem. But is that true? OK, let’s enjoy it.
There are three strings A , B and C. The length of the string A is 2*N, and the length of the string B and C is same to A. You can take N characters from A and take N characters from B. Can you set them to C ?

 

Input

There are several test cases.
Each test case contains three lines A,B,C. They only contain upper case letter.
0<N<100000
The input will finish with the end of file.

 

Output

For each the case, if you can get C, please print “YES”. If you cann’t get C, please print “NO”.

 

Sample Input

AABB
BBCC
AACC
AAAA
BBBB
AAAA

 

 

 

 

 

Sample Output

YES
NO
给三个串,A,B,C.每个字符串的长度相同,都是2*n。
从A,B串中每个串中最多选n个字符。问从A,B中选的
字符能否构成字符串C

设三个数组,分别记录三个字符串中每个字符的数量
再遍历由A,B字符串得到的数组,当字符的数量大于
n时,赋值为n;因为每一个字符串只能贡献n个字符
然后判断两个字符串的字符能否构成c

 

 

#include<string>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;

int as[26],bs[26],cs[26],sta[26];
int main()
{
    string str;
    while(cin>>str)
    {
        memset(as,0,sizeof as);
        memset(bs,0,sizeof bs);
        memset(cs,0,sizeof cs);
        int L=str.length();
        for(int i=0;i<L;i++){
            as[str[i]-'A']++;
        }
        cin>>str;
        for(int i=0;i<L;i++){
            bs[str[i]-'A']++;
        }
        cin>>str;
        for(int i=0;i<L;i++){
            cs[str[i]-'A']++;
        }
        int flag=0;memset(sta,0,sizeof sta);
        for(int i=0;i<26;i++)
        {
            if(as[i]>L/2)as[i]=L/2;
            if(bs[i]>L/2)bs[i]=L/2;
            if(cs[i]>as[i]+bs[i]){
                flag=1;break;
            }
        }
        printf(flag?"NO\n":"YES\n");
    }
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值