0
点赞
收藏
分享

微信扫一扫

高效八股文背诵方法

janedaring 2024-03-29 阅读 9

解题思路:

暴力秒了

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;
    }
}
举报

相关推荐

MySQL八股文(背诵版)

八股文总结

【八股文】小米

前端八股文

Spring八股文

Redis八股文

0 条评论