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:
- # include
- # include
- # include
-
- using namespace std;
-
- int a[1000];
- string s[1000];
-
- int main ()
- {
-
- int t;
- cin>>t;
-
- while(t--)
- {
- int n;
- cin>>n;
- int maxx=1;
- for(int i=1;i<=n;i++)
- {
- cin>>a[i];
- maxx=max(maxx,a[i]);
- s[i]="";
- }
- s[n+1]="";
-
- for(int i=1;i<=maxx;i++)
- {
- s[1]+='a';
-
- }
-
- for(int i=2;i<=n+1;i++)
- {
- {
- s[i]+=s[i-1][j];
- }
- for(int j=a[i-1];j
- {
- if(s[i-1][j]=='a')
- s[i]+='b';
- else
- s[i]+='a';
- }
-
- }
-
- for(int i=1;i<=n+1;i++)
- {
- cout<
- }
-
- }
-
- return 0;
-
- }
-
相关阅读:
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