FJ在沙盘上写了这样一些字符串:
A1 = “A”
A2 = “ABA” 规律:g[]=A,B,C,D,E,F,G........
A3 = “ABACABA” f[n]=f[n-1]+g[n]+f[n-1];
A4 = “ABACABADABACABA”
… …
你能找出其中的规律并写所有的数列AN吗?
输入
仅有一个数:N ≤ 26。
输出
请输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。
样例输入
2 3
样例输出
ABA
ABACABA
#include<bits/stdc++.h>
using namespace std;
string s[30];
string str[30];
void table(){
for(int i=0;i<26;i++){
s[i]='A'+i;
}
str[0]=s[0];
for(int i=1;i<26;i++){
str[i]=str[i-1]+s[i]+str[i-1];
}
}
int main(){
int n;
table();
while(cin>>n){
cout<<str[n-1]<<endl;
}
return 0;
}
string 类型可以拿来直接从左到右进行“相加”操作,不用麻烦的char 数组,直接拼接就行