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