真的很弱智,我tmT了一年,找不出问题在哪里,才发现我每个字符串的for循环都是到strlen(),唉,用cin>>string,习惯了,string真的好蠢.
/* xzppp */
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <list>
#include <math.h>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mp make_pair
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
char a[MAXN+17],b[MAXN+17],c[MAXN+17];
int bn[26+17],cn[26+17],ah[26+17];
int check(int h[26+17],int n[26+17])
{
int res = INF,have[26+17],need[26+17];
for (int i = 0; i < 26; ++i)
{
have[i] = h[i];
need[i] = n[i];
}
for (int i = 0; i < 26; ++i)
{
if(need[i])
{
int temp = have[i]/need[i];
res = min(res,temp);
}
}
return res;
}
int main()
{
//FFF
scanf("%s%s%s",a,b,c);
for (int i = 0; a[i]!='\0'; ++i)
ah[a[i]-'a']++;
for (int i = 0; b[i]!='\0'; ++i)
bn[b[i]-'a']++;
for (int i = 0; c[i]!='\0'; ++i)
cn[c[i]-'a']++;
int bh = check(ah,bn);
int ans = 0,x=0,y=0;
int ori[26+17];
for (int i = 0; i < 26; ++i)
ori[i] = ah[i];
for (int i = 0; i <= bh; ++i)
{
for (int i = 0; i < 26; ++i)
ah[i] = ori[i];
for(int k =0 ;k<26;++k)
ah[k] -= i*bn[k];
int temp = check(ah,cn);
if(i+temp>ans)
{
ans = i+temp;
x = i;
y = temp;
}
}
for (int i = 0; i < x; ++i)
printf("%s",b);
for (int i = 0; i < y; ++i)
printf("%s",c);
for (int i = 0; i < 26; ++i)
ori[i]-=(x*bn[i]+y*cn[i]);
for (int i = 0; i < 26; ++i)
while(ori[i]--) printf("%c",i+'a');
cout<<endl;
return 0;
}