Simple String

本文介绍了一个编程竞赛题目,要求选手判断是否能从两个指定长度的字符串中选取字符来组成第三个字符串。文章提供了一段C++代码实现,详细展示了如何通过统计字符频率来解决这一问题。

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

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");
    }
}

 

使用映射算法将 ER 架构映射到关系数据库架构。使用以下表示法表示生成的关系数据库架构:PK 表示主键,AK 表示备用键,FK 表示外键,并带有指向相应表(主键)的箭头 Book Entity (Strong) - Title (single valued, simple string) - ISBN (single valued, simple alphanumeric string), pk - Edition (single valued, simple numeric) - Date of Publication (single valued, composite concatenation of characters and numbers) - Price (single valued, simple floating point number) - Book Description (single valued, simple string) Author Entity (Strong) - Author Name - Author_id, pk Publisher Entity (Strong) - Publisher id (single value, simple numeric), pk - Publisher Name (single valued, simple string) - Address (single valued, simple string) - together the publisher name and address could make an alternate key because no to publishers can have the same name and address Customer Entity (strong) - Customer_id (single valued, simple string), pk - Name (composite one value for first, middle and last name, simple string) - Mailing Address (single valued, simple string) - Credit Card Number and Expiration Date (single value, simple numeric sequence), alternate key - Phone Number (single value, simple alphanumeric string) - Email Address (single valued, simple alphanumeric string) Shipment (strong) - Date of Shipment ( single valued, composite of strings and numbers) - Tracking Number (single valued, simple alphanumeric string), pk - Date of Expected Delivery ( single valued, compoite of strings and numbers) Order (Strong) - Order Number (single valued, simple number), pk - Mailing Address (single value, simple string) - Method of Shipment (single value, simple string) - Date and Time of Order (when the order was placed) - Total Price of the Order (multivalue, composite) Promotion (strong entity type ) - Promotion id number, pk - Percentage Discount Points (single value, simple float) - Duration of Promotion (start date and end date) ( composite attributes like the dates above) Line Item(weak entity type) - Total price for each book that is ordered (single value, two place precision float) - Quantity of each item ordered Category (strong entity) - Category ID (single value, simple numeric), pk - Category Name (single value, simple string),
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值