蓝桥杯 ALGO-139 算法训练 s01串

xiaoxiao2021-02-28  77

问题描述   s01串初始为"0"   按以下方式变换   0变1,1变01 输入格式   1个整数(0~19) 输出格式   n次变换后s01串 样例输入 3 样例输出 101 数据规模和约定

  0~19

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s1 = "0"; String s2 = ""; if(n!=0) { for(int i=0;i<n;i++) { s2 = ""; int len = s1.length(); for(int j=0;j<len;j++) { char c = s1.charAt(j); s2 = s2.concat(fun(c)); } s1 = s2; } System.out.println(s1); } else { System.out.println("0"); } } public static String fun(char ch) { if(ch=='0') { return "1"; } return "01"; } }

转载请注明原文地址: https://www.6miu.com/read-68554.html

最新回复(0)