蓝桥杯 基础练习 之 FJ的字符串

问题描述
  FJ在沙盘上写了这样一些字符串:
  A1 = “A”
  A2 = “ABA”
  A3 = “ABACABA”
  A4 = “ABACABADABACABA”
  … …
  你能找出其中的规律并写所有的数列AN吗?
输入格式
  仅有一个数:N ≤ 26。
输出格式
  请输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。
样例输入
3
样例输出
ABACABA
 
算法实现:
import java.util.Scanner;
public class Main {
	public static int c;
	public static String[] strings = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		c = sc.nextInt();
		String string = "";
		f(0, "");
	}
	
	public static void f(int index,String str){
		if(index != c){
			str = str + strings[index] +str;
			f(index+1, str);
		}else{
			System.out.println(str);
		}
	}

}

  

原文地址:https://www.cnblogs.com/liuwanqiu/p/6524004.html