题目与解析
考察的小技巧有点多,整体思路除了双指针之外,其他的都有点僵硬,不能算是太有共性的题型
代码解析
java">import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in).useDelimiter("\n");String next = scanner.next();System.out.println(replaceNum(next));scanner.close();}public static String replaceNum(String str) {char[] chars = str.toCharArray();int count = chars.length;for (int i = 0; i < chars.length; i++) {if (Character.isDigit(chars[i])) {count +=5;}}char[] newChars = new char[count];int i=chars.length-1,j=count-1;for (;i>=0;i--,j--) {if (!Character.isDigit(chars[i])) {newChars[j] = chars[i];}else {newChars[j--] = 'r';newChars[j--] = 'e';newChars[j--] = 'b';newChars[j--] = 'm';newChars[j--] = 'u';newChars[j] = 'n';}}return String.valueOf(newChars);}
}