码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces #659 A. Common Prefixes

时间:2020-07-26 00:15:56      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:cas   exist   hoc   tin   void   namespace   lov   一个   元素   

题面

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

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

For each i (1≤i≤n) she calculated ai — the length of the longest common prefix of si and si+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+1 which would have generated numbers a1,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 t (1≤t≤100) — the number of test cases. Description of the test cases follows.

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

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

It is guaranteed that the sum of n over all test cases does not exceed 100.

Output
For each test case:

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

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

Example
inputCopy
4
4
1 2 4 2
2
5 3
3
1 3 1
3
0 0 0
outputCopy
aeren
ari
arousal
around
ari
monogon
monogamy
monthly
kevinvu
kuroni
kurioni
korone
anton
loves
adhoc
problems

思路

从小到大我们去添加或者删除元素十分麻烦,所以我们这里考虑直接给1的位置赋一个长串的a,然后根据题目给定的条件去调整后面一个字母就可以了。

代码实现


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int n;

void solve () {
    string str(200,‘a‘);
    cout<<str<<endl;
    for (int i=0;i<n;i++) {
       int op;
       cin>>op;
       str[op]=str[op]==‘a‘?‘b‘:‘a‘;
       cout<<str<<endl;
    }
}

int main ( ) {

   int t;
   cin>>t;
   while (t--) {
       cin>>n;
       solve ();
   }

    return 0;
}

Codeforces #659 A. Common Prefixes

标签:cas   exist   hoc   tin   void   namespace   lov   一个   元素   

原文地址:https://www.cnblogs.com/hhlya/p/13376612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!