题目链接
题意:
给你一个长度为n的数组,让你构造出n+1个字符串,使得s[i]和s[i+1]之间的最长前缀和等于a[i]。
思路:
首先构造一个长度为60字母全为a的字符串,然后按照输入的a[i]遍历字符串,到达需要改变的位置时,如果该位置是a则变成b,后续有b的情况是b则变成a即可。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+7;
const int M=4e5+8;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
signed main()
{
IOS;
int t;
cin>>t;
while(t--)
{
int n,a[105];
char s[205];
for(int i=0;i<60;i++)
{
s[i]='a';
}
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=0;i<=n;i++)
{
if(i>0)
{
for(int j=0;;j++)
{
if(j==a[i])
{
if(s[j]=='a')
{
s[j]='b';
}
else
{
s[j]='a';
}
break;
}
}
}
for(int j=0;j<60;j++)
{
cout<<s[j];
}
cout<<endl;
}
}
return 0;
}