题解 | #HJ092 在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
http://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.Scanner;
/**
* HJ92 在字符串中找出连续最长的数字串 - 中等
*/
public class HJ092 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
String[] strs = str.split("[^0-9]+");
int max = 0;
for (String s : strs) {
if (s.length() > max) {
max = s.length();
}
}
StringBuffer sb = new StringBuffer();
for (String s : strs) {
if (s.length() == max) {
sb.append(s);
}
}
System.out.println(sb.append(",").append(max));
}
sc.close();
}
}
查看18道真题和解析