1. 程式人生 > 實用技巧 >Common Prefixes

Common Prefixes

構造字串

規定相同字首數目

https://www.ancode.club/index.php/2020/08/07/acm7/

 1 #include<iostream>
 2 #include<string.h>
 3 #include<cmath>
 4 using namespace std;
 5 typedef long long ll;
 6 const int INF=0x3f3f3f3f;
 7 const int N=110;
 8 int T;
 9 int n;
10 int a[N];
11 int main() {
12     ios::sync_with_stdio(false
); 13 scanf("%d",&T); 14 while(T--){ 15 scanf("%d",&n); 16 for(int i=1;i<=n;++i){ 17 scanf("%d",a[i]); 18 } 19 a[n+1]=0; 20 string str; 21 for(int i=0;i<=50;++i){ 22 str +=a; 23 } 24 cout<<str<<endl;
25 for(int i=2;i<=n+1;++i){ 26 string str2; 27 for(int j=0;j<a[i-1];++j){ 28 str2+=str[j]; 29 } 30 for(int j=a[i-1];j<=50;j++){ 31 for(char ch='a';ch<='z';ch++){ 32 if(ch!=str[j]){ 33
str2+=ch; 34 break; 35 } 36 } 37 } 38 str=str2; 39 cout<<str<<endl; 40 } 41 } 42 return 0; 43 }