题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.HashMap; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int res = 0; String str = sc.nextLine(); HashMap<Integer, String>hs = new HashMap<>(); for (String s : str.split("\\D")) { hs.put(s.length(), hs.getOrDefault(s.length(), "") + s); } for (Integer i : hs.keySet()) { res = Math.max(res, i); } System.out.println(hs.get(res) + "," + res); } } }