題目描述
FJ在沙盤上寫了這樣一些字符串:
A1 = “A”
A2 = “ABA”
A3 = “ABACABA”
A4 = “ABACABADABACABA”
… …
你能找出其中的規律並寫所有的數列AN嗎?
輸入
僅有一個數:N ≤ 26。
輸出
請輸出相應的字符串AN,以一個換行符結束。輸出中不得含有多餘的空格或換行、回車符。
樣例輸入
3
樣例輸出
ABACABA
#include<iostream>
using namespace std;
string AN(int n)
{
int x=n;
string str="";
if(n==1)
{
str="A";
return str;
}
else
{
str+=AN(n-1);
str+=(char)('A'+x-1);
str+=AN(n-1);
}
return str;
}
int main()
{
int n;
cin>>n;
cout<<AN(n);
return 0;
}