第一题
package ccf201912; import java.util.Scanner; public class p1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] p = new int[4]; int count = 1; int num = 1; while (count < n) { for (int i = 0; i < 4; i++) { if (hasSeven(num)) { p[i]++; count--; } if (count >= n) break; num++; count++; } } for (int i = 0; i < 4; i++) { System.out.println(p[i]); } } public static boolean hasSeven(int num) { if (num % 7 == 0) { return true; } String str = "" + num; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '7') { return true; } } return false; } }
第二题
package ccf201912; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class p2 { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] temp = bf.readLine().split(" "); int n = Integer.parseInt(temp[0]); long[] x = new long[n + 1]; long[] y = new long[n + 1]; long[] count = new long[n + 1]; int[] res = new int[5]; for (int i = 1; i <= n; i++) { String[] line = bf.readLine().split(" "); x[i] = Integer.parseInt(line[0]); y[i] = Integer.parseInt(line[1]); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (x[j] == x[i] && y[j] == y[i] - 1) { count[i]++; count[j]++; } if (x[j] == x[i] && y[j] == y[i] + 1) { count[i]++; count[j]++; } if (x[j] == x[i] - 1 && y[j] == y[i]) { count[i]++; count[j]++; } if (x[j] == x[i] + 1 && y[j] == y[i]) { count[i]++; count[j]++; } } } for (int i = 1; i <= n; i++) { if (count[i] >= 4) { for (int j = 1; j <= n; j++) { if (x[j] == x[i] - 1 && y[j] == y[i] - 1) { count[i]++; } if (x[j] == x[i] - 1 && y[j] == y[i] + 1) { count[i]++; } if (x[j] == x[i] + 1 && y[j] == y[i] - 1) { count[i]++; } if (x[j] == x[i] + 1 && y[j] == y[i] + 1) { count[i]++; } } } } for (int i = 1; i <= n; i++) { if (count[i] >= 4) { if (count[i] - 4 == 0) { res[0]++; } else if (count[i] - 4 == 1) { res[1]++; } else if (count[i] - 4 == 2) { res[2]++; } else if (count[i] - 4 == 3) { res[3]++; } else if (count[i] - 4 == 4) { res[4]++; } } } for (int i = 0; i < 5; i++) { System.out.println(res[i]); } } }