CSU Rectangle (模拟)

题目链接:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 1000010
int cnta[30],cntb[30],cntc[30];
char a[maxn],b[maxn],c[maxn];
int main()
{
   while(~scanf("%s%s%s",a,b,c))
   {
       int lena=strlen(a);
       int lenb=strlen(b);
       int lenc=strlen(c);
       memset(cnta,0,sizeof(cnta));
       memset(cntb,0,sizeof(cntb));
       memset(cntc,0,sizeof(cntc));
       for(int i=0;i<lena;i++)
       {
           cnta[a[i]-'A'+1]++;
       }
       for(int i=0;i<lenb;i++)
       {
           cntb[b[i]-'A'+1]++;
       }
       for(int i=0;i<lenc;i++)
       {
           cntc[c[i]-'A'+1]++;
       }
       int mina=0;
       int minb=0;
       int flag=0;
       for(int i=1;i<=26;i++)
       {
           if(cnta[i]+cntb[i]<cntc[i])
           {
               printf("NO\n");
               flag=1;
               break;
           }
           mina+=min(cnta[i],cntc[i]);
           minb+=min(cntb[i],cntc[i]);
       }
       if(flag)
        continue;
       if(mina>=lenc/2&&minb>=lenc/2)
       {
           printf("YES\n");
       }
       else
       {
           printf("NO\n");
       }
}
 return 0;
}

 

点赞