HUA_1-3 FJ的字符串

FJ的字符串

Description:

FJ在沙盘上写了这样一些字符串:  A1 = “A”  A2 = “ABA”  A3 = “ABACABA”  A4 = “ABACABADABACABA”  … …  你能找出其中的规律并写所有的数列AN吗?

Input

仅有一个数:N ≤ 26。

Output

请输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。

Sample Input 1

1
3

Sample Output 1

1
ABACABA

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
using namespace std;
//将字符串分为左中右,无非是添加第n个字母,原理有点像奥利奥
int main() {
//大写字母A的ascii编码65,a是97
int n;
string left, out_s;
char c = 65;
scanf("%d", &n);

for (int i = 0;i < n;i++) {
if (i == 0) {
out_s = c;
continue;
}
left = out_s;
out_s += (c + i);
out_s.append(left);
}

printf("%s\n",out_s.c_str());
return 0;
}

----\(˙<>˙)/----赞赏一下吧~