时间限制:1.0s   内存限制:256.0MB
  s01串初始为"0"
按以下方式变换
0变1,1变01
按以下方式变换
0变1,1变01
  1个整数(0~19)
  n次变换后s01串
3
101
  0~19
import java.util.*;
public class s01串 {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String x = "0"; //开局一个0,结果全靠编
		//循环次数为n次
		for (int i = 0; i < n; i++) {
			//循环调用
			x = s(x);
		}
		System.out.println(x);
	}
	static String s(String x) {
		//创建一个stringbuilder来装每次循环的结果
		StringBuilder y = new StringBuilder();
		//遍历字符串x,根据题意判断
		for (int j = 0; j < x.length(); j++) {
			char z = x.charAt(j);
			if (z == '0') {
				y.append("1");
			} else if (z == '1') {
				y.append("01");
			}
		}
		//转为字符串,并返回
		x = y.toString();
		return x;
	}
} 
        
       
     
      
评论 (0)