{"id":1265,"date":"2022-06-04T09:44:07","date_gmt":"2022-06-04T01:44:07","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1265"},"modified":"2022-06-04T09:44:07","modified_gmt":"2022-06-04T01:44:07","slug":"hj90-%e5%90%88%e6%b3%95ip","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/06\/04\/hj90-%e5%90%88%e6%b3%95ip\/","title":{"rendered":"HJ90 \u5408\u6cd5IP"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u63cf\u8ff0<\/h2>\n\n\n\n<p>IPV4\u5730\u5740\u53ef\u4ee5\u7528\u4e00\u4e2a32\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u6765\u8868\u793a\uff0c\u4e00\u822c\u7528\u70b9\u5206\u65b9\u5f0f\u6765\u663e\u793a\uff0c\u70b9\u5c06IP\u5730\u5740\u5206\u62104\u4e2a\u90e8\u5206\uff0c\u6bcf\u4e2a\u90e8\u5206\u4e3a8\u4f4d\uff0c\u8868\u793a\u6210\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570\uff08\u56e0\u6b64\u6b63\u53f7\u4e0d\u9700\u8981\u51fa\u73b0\uff09\uff0c\u598210.137.17.1\uff0c\u662f\u6211\u4eec\u975e\u5e38\u719f\u6089\u7684IP\u5730\u5740\uff0c\u4e00\u4e2aIP\u5730\u5740\u4e32\u4e2d\u6ca1\u6709\u7a7a\u683c\u51fa\u73b0\uff08\u56e0\u4e3a\u8981\u8868\u793a\u6210\u4e00\u4e2a32\u6570\u5b57\uff09\u3002\u73b0\u5728\u9700\u8981\u4f60\u7528\u7a0b\u5e8f\u6765\u5224\u65adIP\u662f\u5426\u5408\u6cd5\u3002<br>\u6570\u636e\u8303\u56f4\uff1a\u6570\u636e\u7ec4\u6570\uff1a1\u2264<em>t<\/em>\u226418\u00a0<br>\u8fdb\u9636\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n)\\<em>O<\/em>(<em>n<\/em>)\u00a0\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(n)\\<em>O<\/em>(<em>n<\/em>)\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u8f93\u5165\u4e00\u4e2aip\u5730\u5740\uff0c\u4fdd\u8bc1\u4e0d\u5305\u542b\u7a7a\u683c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u8fd4\u56de\u5224\u65ad\u7684\u7ed3\u679cYES&nbsp;or&nbsp;NO<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b1<\/h2>\n\n\n\n<p>\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">255.255.255.1000\n<\/pre>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">NO\n<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\npublic class Main{\n    public static void main(String&#91;] args){\n        Scanner sc = new Scanner(System.in);\n        while(sc.hasNext()){\n            String&#91;] str = sc.nextLine().split(\"\\\\.\");\n            boolean flag = true;\n            if(str.length == 4){\n                for(int i = 0; i &lt; 4; i++){\n                    if(str&#91;i].equals(\"\")){\n                        flag = false;\n                        break;\n                    }else if(str&#91;i].length()>1 &amp;&amp; str&#91;i].charAt(0)=='0'){\n                        flag = false;\n                        break;\n                    }else if(str&#91;i].replaceAll(\"&#91;0-9]\",\"\").length() != 0){\n                        flag = false;\n                        break;\n                    }else if(Integer.parseInt(str&#91;i])&lt;0 || Integer.parseInt(str&#91;i])>255){\n                        flag = false;\n                        break;\n                    }else{\n                        flag = true;\n                    }\n                }\n            }else{\n                flag = false;\n            }\n            \n          System.out.println(flag ? \"YES\" : \"NO\");  \n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>\u7528&#8217;.&#8217;\u622a\u53d6\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u5e94\u8be5\u628aip\u5206\u6210\u56db\u4e2a\u5b50\u4e32\u3002\u7136\u540e\u5206\u522b\u5bf9\u8fd9\u56db\u4e2a\u5b50\u4e32\u8fdb\u884c\u68c0\u9a8c\uff1a\u68c0\u9a8c\u7684\u9879\u76ee\u67091\u3001\u975e\u7a7a\u68c0\u9a8c\uff1b2\u3001\u975e\u96f6\u6570\u662f\u5426\u542b\u6709\u524d\u5bfc\u96f6\uff1b3\u3001\u662f\u5426\u542b&#8217;+&#8217;\u53f7\uff1b4\u3001\u662f\u5426\u57280-255\u4e4b\u95f4\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\/*\n\u7528'.'\u622a\u53d6\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u5e94\u8be5\u628aip\u5206\u6210\u56db\u4e2a\u5b50\u4e32\u3002\n\u7136\u540e\u5206\u522b\u5bf9\u8fd9\u56db\u4e2a\u5b50\u4e32\u8fdb\u884c\u68c0\u9a8c\uff1a\u68c0\u9a8c\u7684\u9879\u76ee\u6709\n1\u3001\u975e\u7a7a\u68c0\u9a8c\uff1b\n2\u3001\u975e\u96f6\u6570\u662f\u5426\u542b\u6709\u524d\u5bfc\u96f6\uff1b\n3\u3001\u662f\u5426\u542b'+'\u53f7\uff1b\n4\u3001\u662f\u5426\u57280-255\u4e4b\u95f4\u3002\n*\/\npublic class Main {\n    public static void main(String&#91;] args) {\n        Scanner in = new Scanner(System.in);\n        boolean isValid= true;\n        while (in.hasNext()) { \n            String s = in.nextLine();\n            String ips&#91;] = s.split(\"\\\\.\");\n            if(ips.length!=4){\n                isValid = false;\n                break;\n            }\n            for(int i =0;i&lt;ips.length;++i){\n                if(check(ips&#91;i])){\n                   isValid = false;\n                    break;\n                }\n            }\n        }\n        if(isValid)\n             System.out.println(\"YES\");\n        else  System.out.println(\"NO\");\n    }\n    public static boolean check(String s){\n        if(s.equals(\"\"))return true;\n        int temp =Integer.parseInt(s);\n        if(temp!=0&amp;&amp;s.charAt(0)=='0')return true;\n        else if(s.charAt(0)=='+')return true;\n        else if(temp&lt;0||temp>=255)return true;\n        return false;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u63cf\u8ff0 IPV4\u5730\u5740\u53ef\u4ee5\u7528\u4e00\u4e2a32&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-1265","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1265"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1265\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1257"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}