Boge
BAN USERpublic static String foo(String encoded, int index) {
// next number
int next = 0;
// current digit
int start = -1;
// number of letters between the two adjacent digit
int span = 0;
// current total letters
int total = 0;
for (int i = 0; i < encoded.length(); i++) {
// if the char is digit
if (Character.isDigit(encoded.charAt(i))) {
next = Character.getNumericValue(encoded.charAt(i));
span = (i - start) - 1;
total += span * next;
if (total <= index) {
start = i;
continue;
} else {
int which = total - index;
return encoded.substring(start + 1 + (which % span), start
+ 1 + (which % span) + 1);
}
}
}
if (index >= total) {
System.out.println("Sorry, the index is out of bound");
}
return null;
}
}
public static String foo(String encoded, int index) {
- Boge February 03, 2015// next number
int next = 0;
// current digit
int start = -1;
// number of letters between the two adjacent digit
int span = 0;
// current total letters
int total = 0;
for (int i = 0; i < encoded.length(); i++) {
// if the char is digit
if (Character.isDigit(encoded.charAt(i))) {
next = Character.getNumericValue(encoded.charAt(i));
span = (i - start) - 1;
total += span * next;
if (total <= index) {
start = i;
continue;
} else {
int which = total - index;
return encoded.substring(start + 1 + (which % span), start
+ 1 + (which % span) + 1);
}
}
}
if (index >= total) {
System.out.println("Sorry, the index is out of bound");
}
return null;
}
}