解题思路:
暴力秒了
public class Main {public static void main(String[] args) {int cnt = 0;for (int i = 1900; i <= 9999; i++) {for (int j = 1; j <= 12; j++) {for (int k = 1; k <= days(i, j); k++) {if (sum(i) == sum(j) + sum(k)) cnt++;}}}System.out.print(cnt);}public static int days(int i, int j) {if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12)return 31;if (j == 4 || j == 6 || j == 9 || j == 11)return 30;if (j == 2 && i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))return 29;return 28;}public static int sum(int x) {int s = 0;while (x != 0) {s += x % 10;x /= 10;}return s;}
}