字节笔试第四题
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String num = in.nextLine(); ArrayList<StringBuilder> list = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); decode(num, 0, stringBuilder, list); for (StringBuilder str : list) { System.out.println(str.toString()); } System.out.println(list.size()); } private static void decode(String num, int start, StringBuilder stringBuilder, ArrayList<StringBuilder> list) { int length = num.length(); if (start >= length) { list.add(stringBuilder); return; } char c = num.charAt(start); if (c == '0') { return; } stringBuilder.append((char) ('A' + Integer.parseInt(num.substring(start, start + 1)) - 1)); decode(num, start + 1, new StringBuilder(stringBuilder), list); stringBuilder.deleteCharAt(stringBuilder.length()-1); if (start + 1 < length && (c == '1' || (c == '2' && num.charAt(start + 1) < '7'))) { stringBuilder.append((char) ('A' + Integer.parseInt(num.substring(start, start + 2)) - 1)); decode(num, start + 2, new StringBuilder(stringBuilder), list); } } }
#笔试题目##字节跳动#