当前位置:网站首页>A. Common Prefixes
A. Common Prefixes
2022-08-09 21:55:00 【秦小咩】
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
# include<iostream> # include<string.h> # include<vector> 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++) { for(int j=0;j<a[i-1];j++) { s[i]+=s[i-1][j]; } for(int j=a[i-1];j<maxx;j++) { if(s[i-1][j]=='a') s[i]+='b'; else s[i]+='a'; } } for(int i=1;i<=n+1;i++) { cout<<s[i]<<endl; } } return 0; }
边栏推荐
- 台风生成,广州公交站场积极开展台风防御安全隐患排查
- 力扣 1413. 逐步求和得到正数的最小值
- mysql 找不到或无法加载已注册的 .Net Framework Data Provider。
- FileZilla搭建FTP服务器图解教程
- Let's talk about what DDL, DML, DQL and DCL are in SQL statements
- random.normal() and random.truncated_normal() in TF
- TF generates uniformly distributed tensor
- openGauss数据库基本操作(超详细)
- Js fifteen interview questions (with answers)
- 4D Summary: 38 Knowledge Points of Distributed Systems
猜你喜欢

Under the NVM node installation;The node environment variable configuration

xctf攻防世界 Web高手进阶区 ics-05
![This article lets you quickly understand implicit type conversion [integral promotion]!](/img/16/4edc7ef23384b22d50ebd894b8911a.png)
This article lets you quickly understand implicit type conversion [integral promotion]!

SQLi-LABS Page-2 (Adv Injections)

Flask入门学习教程

JS解混淆-AST还原案例

Five Star Holdings Wang Jianguo: Deepen the track with "plant spirit" and promote growth with "animal spirit"

leetcode 38. 外观数列

JS Deobfuscation - AST Restoration Case
6 rules to sanitize your code
随机推荐
Technology Sharing | How to use the JSON Schema mode of interface automation testing?
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
js数组对象去重
Blender程序化建模简明教程【PCG】
腾讯继续挥舞降本增效“大刀”,外包员工免费餐饮福利被砍了
TF uses constant to generate data
Presto Event Listener开发
【GORM】模型关系-HasMany关系
【EF】 更新条目时出错。有关详细信息,请参见内部异常。[通俗易懂]
OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
SecureCRT sets the timeout period for automatic disconnection
String hashing (2014 SERC J question)
金山云地震,震源在字节?
简单问题窥见数学
[Implementation of the interface for adding, deleting, checking, and modifying a double-linked list]
国内手机厂商曾为它大打出手,如今它却最先垮台……
Reinforcement Learning Weekly Issue 57: DL-DRL, FedDRL & Deep VULMAN
JS解混淆-AST还原案例
17-GuliMall 搭建虚拟域名访问环境
编译原理之文法