蓝桥杯FJ字符串

问题描述

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

输入格式

仅有一个数:N ≤ 26。

输出格式

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

样例输入

3

样例输出

ABACABA

这里我们注意 ‘A’+2 输出的是数字(ASCII码)要想输出字母需要前面转化成(char)(‘A’+2) 此外string 是可以与char直接相加的
#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;
//int s=0;
//char p[] = {'ling','yi','er','san','si','wu','liu','qi','ba','jiu'};
//char dw[] = {'shi','bai','qian','wan','shi','bai','qian','yi','shi'};

string f(int n){
    
    
	if(n == 1){
    
    
		return "A";
	}
	else{
    
    
		return f(n-1) + (char)('A'+n-1)+f(n-1); 
	}
}
int main()
{
    
    
	int n;
	cin >> n;
	cout << f(n) <<endl;
	cout << (char)('A'+2);
//	string p = "ASD";
//	char d = 'H';
//	cout << p+d;
	//cout << s <<endl;	
	return 0;
	
}

猜你喜欢

转载自blog.csdn.net/weixin_44044395/article/details/115796560
今日推荐