/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
*/
package com.nowcoder;
import java.util.Scanner;
import java.util.regex.Pattern;
/**
* @author lushuifa
* @version [版本号, 2022年05月05日}]
* @ClassName : HJ90
* @Description : IP合法性
*
* @since [2022-04-01]
*/
public class HJ90 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 while 处理多个 case
while (in.hasNext()) {
boolean checkFlag = checkIp(in.nextLine());
System.out.println(checkFlag?"YES":"NO");
}
}
private static boolean checkIp(String inputString){
String[] ipArray = inputString.split("\\.");
if (ipArray.length!=4) {
return Boolean.FALSE;
}
for (int i = 0; i < ipArray.length; i++) {
if(null==ipArray[i] || ipArray[i].trim().equals("")){
return Boolean.FALSE;
}
if(ipArray[i].length()>1&&ipArray[i].startsWith("0")){
return Boolean.FALSE;
}
Pattern pattern = Pattern.compile("[0-9]*");
// 判断每段都是数字
boolean matchFlag = pattern.matcher(ipArray[i]).matches();
if(!matchFlag){
return Boolean.FALSE;
}
// 判断大小
int subIp = Integer.parseInt(ipArray[i]);
if(subIp<0 || subIp>255){
return Boolean.FALSE;
}
}
return Boolean.TRUE;
}
}