题意:把a1bc3d1字符串输出为aabcbcbcd
输入:a1bc3d1
输出:aabcbcbcd
public static String show(String string) {
String word = "";
StringBuilder sb = new StringBuilder();
for(int i=0; i<string.length(); i++) {
String temp = string.charAt(i)+"";
if(temp.matches("[a-z]")) {
sb.append(temp);
word += temp; // 把匹配好字符串临时保存
}else {
int times = Integer.parseInt(temp);
for(int j=1; j<times; j++) {
sb.append(word); //根据出现的数字对临时保存的字符串再次拼接
}
word = "";
}
}
return sb.toString();