题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { char[] chars = str.toCharArray(); StringBuilder sb = new StringBuilder(); String reg = "\\d"; int j = 0; int flag = 0; loop: for (int i = 0; i < chars.length; i++) { String s = chars[i] + ""; if (s.matches(reg)) { sb.append("*").append(chars[i]); j = i + 1; if (j == chars.length) { sb.append("*"); break; } while (chars[j] >= '0' && chars[j] <= '9') { sb.append(chars[j]); flag = 1; j++; if (j == chars.length) { sb.append("*"); break loop; } } if (flag == 0) { sb.append("*").append(chars[j]); i = j; } if (flag == 1) { sb.append("*").append(chars[j]); i = j; flag = 0; } } else { sb.append(chars[i]); } } System.out.println(sb.toString()); } } }