A. Lex String
分析
a,b两个字符串,n,m分别是他们的长度。每次可以从他们之中取一个字符构成新串,不能连续k次从同一个字符串中取字符,求构成字典序最小的字符串。
字典序最小:优先字母顺序,并不是长度短的更小(碎碎念:每次遇到字典序最小都要写一遍)
用字符数组存储a,b两个字符串,对两个字符串按字典序排序后,从前往后像答案字符串添加。按题意模拟出答案字符串。
(碎碎念:写代码太烂真的是我的错55555)
代码
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define guanliu ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const ll maxn=2e5+10;
const ll mod=1e9+7;
const ll INF=0x3f3f3f3f;
const double pi=acos(-1);
char a[150],b[150],ans[300];
bool cmp(char a,char b)
{
return a<b;
}
int main()
{
guanliu;
int t;
cin>>t;
while(t--)
{
int n,m,k;
int cnt=0;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
sort(a+1,a+1+n,cmp);
sort(b+1,b+1+m,cmp);
int i=1,j=1;
int tt=0;
int op=0;
while(n&&m)
{
if(tt==k)
{
if(op==1)
{
ans[++cnt]=b[j++];
op=2;
tt=1;
m--;
}
else {
ans[++cnt]=a[i++];
op=1;
tt=1;
n--;
}
}
else {
if(a[i]<b[j])
{
n--;
ans[++cnt]=a[i++];
if(op==1) tt++;
else {
op=1;
tt=1;
}
}
else {
m--;
ans[++cnt]=b[j++];
if(op==2) tt++;
else {
op=2;
tt=1;
}
}
}
}
for(int i=1;i<=cnt;i++)
{
cout<<ans[i];
}
cout<<endl;
}
return 0;
}
不想补了、、、后面的想起来再补好了、、、