题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); String regStr = "((2[0-4]\\d|25[0-5]|1\\d{2}|[1-9]\\d|\\d)\\.){3}(2[0-4]\\d|25[0-5]|1\\d{2}|[1-9]\\d|\\d)"; if(str.matches(regStr)){ System.out.println("YES"); }else{ System.out.println("NO"); } } }