public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String str = "aa2bc1d10";
        System.out.println(decode(str));
    }

    public static String decode(String str) {
        StringBuffer sb = new StringBuffer();
        StringBuffer tempBuffer = new StringBuffer();
        int numStart = 0;
        int numEnd = 0;
        int times = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (!Character.isDigit(c)) {
                tempBuffer.append(c);
            } else {
                if ((i - 1) >= 0 && !Character.isDigit(str.charAt(i - 1))) {
                    numStart = i;
                }
                if ((i + 1) < str.length()
                        && !Character.isDigit(str.charAt(i + 1))) {
                    numEnd = i + 1;
                }
                if ((i + 1) == str.length()) {
                    numEnd = i + 1;
                }
                if (numEnd != 0) {
                    times = Integer.parseInt(str.substring(numStart, numEnd));
                    for (int j = 0; j < times; j++) {
                        sb.append(tempBuffer);
                    }
                    tempBuffer.delete(0, tempBuffer.length());
                    numEnd = 0;
                }
            }
        }
        return sb.toString();
    }
}