• A. Common Prefixes


    A. Common Prefixes

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    The length of the longest common prefix of two strings s=s1s2…sns=s1s2…sn and t=t1t2…tmt=t1t2…tm is defined as the maximum integer kk (0≤k≤min(n,m)0≤k≤min(n,m)) such that s1s2…sks1s2…sk equals t1t2…tkt1t2…tk.

    Koa the Koala initially has n+1n+1 strings s1,s2,…,sn+1s1,s2,…,sn+1.

    For each ii (1≤i≤n1≤i≤n) she calculated aiai — the length of the longest common prefix of sisi and si+1si+1.

    Several days later Koa found these numbers, but she couldn't remember the strings.

    So Koa would like to find some strings s1,s2,…,sn+1s1,s2,…,sn+1 which would have generated numbers a1,a2,…,ana1,a2,…,an. Can you help her?

    If there are many answers print any. We can show that answer always exists for the given constraints.

    Input

    Each test contains multiple test cases. The first line contains tt (1≤t≤1001≤t≤100) — the number of test cases. Description of the test cases follows.

    The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the number of elements in the list aa.

    The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤500≤ai≤50) — the elements of aa.

    It is guaranteed that the sum of nn over all test cases does not exceed 100100.

    Output

    For each test case:

    Output n+1n+1 lines. In the ii-th line print string sisi (1≤|si|≤2001≤|si|≤200), consisting of lowercase Latin letters. Length of the longest common prefix of strings sisi and si+1si+1 has to be equal to aiai.

    If there are many answers print any. We can show that answer always exists for the given constraints.

    Example

    input

    Copy

    4
    4
    1 2 4 2
    2
    5 3
    3
    1 3 1
    3
    0 0 0
    

    output

    Copy

    aeren
    ari
    arousal
    around
    ari
    monogon
    monogamy
    monthly
    kevinvu
    kuroni
    kurioni
    korone
    anton
    loves
    adhoc
    problems

    Note

    In the 11-st test case one of the possible answers is s=[aeren,ari,arousal,around,ari]s=[aeren,ari,arousal,around,ari].

    Lengths of longest common prefixes are:

    • Between aerenaeren and ariari →1→1
    • Between ariari and arousalarousal →2→2
    • Between arousalarousal and aroundaround →4→4
    • Between aroundaround and ariari →2
    • ======================================================================
    • 把第一个构造成全是a,其余直接根据a[i]构造即可,保证前缀相等的同时,其余全部搞成相反的(a->b,b->a),长度最小是1
      1. # include
      2. # include
      3. # include
      4. using namespace std;
      5. int a[1000];
      6. string s[1000];
      7. int main ()
      8. {
      9. int t;
      10. cin>>t;
      11. while(t--)
      12. {
      13. int n;
      14. cin>>n;
      15. int maxx=1;
      16. for(int i=1;i<=n;i++)
      17. {
      18. cin>>a[i];
      19. maxx=max(maxx,a[i]);
      20. s[i]="";
      21. }
      22. s[n+1]="";
      23. for(int i=1;i<=maxx;i++)
      24. {
      25. s[1]+='a';
      26. }
      27. for(int i=2;i<=n+1;i++)
      28. {
      29. for(int j=0;j-1];j++)
      30. {
      31. s[i]+=s[i-1][j];
      32. }
      33. for(int j=a[i-1];j
      34. {
      35. if(s[i-1][j]=='a')
      36. s[i]+='b';
      37. else
      38. s[i]+='a';
      39. }
      40. }
      41. for(int i=1;i<=n+1;i++)
      42. {
      43. cout<
      44. }
      45. }
      46. return 0;
      47. }

  • 相关阅读:
    ubunu中配置torch环境4060显卡
    python面试题——版本管理工具GIT(二)
    Python零基础速成班-第16讲-Python for Matplotlib 线图、散点图、柱形图、饼图
    springboot jar包瘦身
    高仿英雄联盟游戏网页制作作业 英雄联盟LOL游戏HTML网页设计模板 简单学生网页设计 静态HTML CSS网站制作成品
    MySQL数据库
    Spring Cloud Gateway转发Spring WebSocket
    数据可视化:四种关系图数据可视化的效果对比!
    初学者使用R语言读取excel/csv/txt的注意事项
    STL-stack、queue和priority_queue的模拟实现
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126247293