基础练习 FJ的字符串

试题 基础练习 FJ的字符串

资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
  FJ在沙盘上写了这样一些字符串:
  A1 = “A”
  A2 = “ABA”
  A3 = “ABACABA”
  A4 = “ABACABADABACABA”
  … …
  你能找出其中的规律并写所有的数列AN吗?
输入格式
  仅有一个数:N ≤ 26。
输出格式
  请输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。
样例输入
3
样例输出
ABACABA

package lanqiaozhenti;
import java.util.*;
public class FJ的字符串 {

public static void main(String[] args) {
	Scanner in =new Scanner(System.in);
	m=in.nextInt();
	str[1]=s[0];
	if(m==1) {
		str[1]=s[0];
		System.out.printf("%s\n",s[0]);
	}else {
		print(2);
		System.out.printf("%s\n",str[m]);
	}

}
static String[] s= {"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"};
static String[] str=new String[27];
static int m;
static void print(int n) {
	if(n>m) {
		return;
	}
	if(n<=m) {
		str[n]=str[n-1]+s[n-1]+str[n-1];
		//System.out.println(str[n]);
		print(n+1);
	}
}

}

你可能感兴趣的:(基础练习 FJ的字符串)