1808: FJ的字符串
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 85 Solved: 59
[Submit][Status][Web Board]
Description
FJ在沙盘上写了这样一些字符串:
A1 = “A” A2 = “ABA” A3 = “ABACABA” A4 ==“ABACABADABACABA” … …
你能找出其中的规律并写所有的数列AN吗?
Input
仅有一个数:N ≤ 26。
Output
输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。
Sample Input
3
Sample Output
ABACABA
//用C++写啦
Ac_code:
#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
string s1,s2;
s1 = s2 = "A";
char m = 'B';
n--;
while(n--)
{
s2 = s1 + m + s1;
s1 = s2;
m++;
}
cout<<s2<<endl;
}
return 0;
}