1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
自行实现
public class HJ092 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String[] ans = getLongestDigitChar(sc.nextLine());
System.out.println(ans[0] + "," + ans[1]);
}
}
public static String[] getLongestDigitChar(String str) {
String[] ans = new String[2];
int max = 0;
StringBuffer sb = new StringBuffer();
int i = 0;
char[] chars = str.toCharArray();
while (i < chars.length) {
char c = chars[i];
if (!Character.isDigit(c)) {
i++;
continue;
}
int curCnt = 0;
while (i < chars.length && Character.isDigit(chars[i])) {
curCnt++;
i++;
}
String cur = str.substring(i - curCnt, i);
if (curCnt > max) {
max = curCnt;
sb = new StringBuffer(cur);
} else if (curCnt == max) {
sb.append(cur);
}
}
ans[0] = sb.toString();
ans[1] = max + "";
return ans;
}
}