B. Following the String

题解

我们从左向右构建字符串。

每种数字我们都从a开始取,接下来我们用一个数组来存储对应数字下一次要取的字母。

Code

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int b[N],a[N];
int main(){
    int t;
    cin>>t;
    while (t--){
        memset(b,0,sizeof(b));
        string s;
        int n;
        cin>>n;
        for (int i=1;i<=n;i++){
            cin>>a[i];
            s+='a'+b[a[i]];
            b[a[i]]++;
        }
        cout<<s<<endl;
    }
    return 0;
}

 

posted @ 2024-02-09 18:55  黑屿白  阅读(37)  评论(0)    收藏  举报