rambless
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String str = in.nextLine(); System.out.println(match(str)); } } private static String match(String str) { String[] arr = str.split("\\."); if(arr.length != 4) { return "NO"; } for(int i=0; i<arr.length; i++) { if(arr[i].length() == 0) { return "NO"; } if(arr[i].startsWith("+") || arr[i].startsWith("-")) { return "NO"; } if(arr[i].length()>3) { return "NO"; } if(arr[i].startsWith("0") && arr[i].length()>1) { return "NO"; } if(Integer.parseInt(arr[i])>255) { return "NO"; } } return "YES"; } }