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.hasNextInt()) { // 注意 while 处理多个 case // int a = in.nextInt(); // int b = in.nextInt(); // System.out.println(a + b); // } int[] counts = new int[7]; while (in.hasNextLine()) { String line = in.nextLine(); String[] ip = line.split("~")[0].split("\\."); if (ip.length != 4) { counts[5]++; continue; } int ip0 = 0, ip1 = 0, ip2 = 0, ip3 = 0; int code0 = 0, code1 = 0, code2 = 0, code3 = 0; try { ip0 = Integer.parseInt(ip[0]); ip1 = Integer.parseInt(ip[1]); ip2 = Integer.parseInt(ip[2]); ip3 = Integer.parseInt(ip[3]); if (ip0 == 0 || ip0 == 127) { continue; } String[] code = line.split("~")[1].split("\\."); code0 = Integer.parseInt(code[0]); code1 = Integer.parseInt(code[1]); code2 = Integer.parseInt(code[2]); code3 = Integer.parseInt(code[3]); } catch (NumberFormatException e) { counts[5]++; continue; } // 判断子网掩码是否合法 StringBuilder builder = new StringBuilder(); String codeBinary = builder.append(toBinary(code0)) .append(toBinary(code1)) .append(toBinary(code2)) .append(toBinary(code3)) .toString(); if (codeBinary.contains("01") || !codeBinary.contains("0") || !codeBinary.contains("1")) { counts[5]++; continue; } boolean b = ip1 >= 0 && ip1 <= 255 && ip2 >= 0 && ip2 <= 255 && ip3 >= 0 && ip3 <= 255; if (!b) { counts[5]++; continue; } if (ip0 >= 1 && ip0 <= 126) { counts[0]++; } else if (ip0 >= 128 && ip0 <= 191) { counts[1]++; } else if (ip0 >= 192 && ip0 <= 223) { counts[2]++; } else if (ip0 >= 224 && ip0 <= 239) { counts[3]++; } else if (ip0 >= 240 && ip0 <= 255) { counts[4]++; } else { counts[5]++; continue; } if (ip0 == 10) { counts[6]++; } else if (ip0 == 172 && ip1 >= 16 && ip1 <= 31) { counts[6]++; } else if (ip0 == 192 && ip1 == 168) { counts[6]++; } } System.out.print(counts[0] + " " + counts[1] + " " + counts[2] + " " + counts[3] + " " + counts[4] + " " + counts[5] + " " + counts[6]); } private static String toBinary(int n) { String binary = Integer.toBinaryString(n); for (int i = 0; i < 8 - binary.length(); i++) { binary = "0" + binary; } return binary; } }