CF1927B Following the String solution
形式化题意:给定一个长度为 a-z )在区间 a-z 组成。
由题意可知,a-z 出现的次数就可以了。可以用一个数组 cnt 统计 a-z 的出现次数,然后每次求 cnt ,如果发现有一个 cnt[j]==a[i] 的字母,就把 cnt[j]++ ,然后输出并跳出循环。
因为题目中说了数据保证有解,所以不需要考虑无解的情况。
时间复杂度
code:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=2e5+5;
int T;
int n;
int a[MAXN];
int cnt[200];
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>T;
while(T--)
{
memset(cnt,0,sizeof(cnt));
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i];
for(int j='a';j<='z';++j)
{
if(cnt[j]==a[i])
{
++cnt[j];
cout<<(char)(j);
break;
}
}
}
cout<<'\n';
}
return 0;
}