题解 | 计算日期到天数转换

计算日期到天数转换

https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

import java.util.Scanner;

import java.util.HashMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(0, 0);
        map.put(1, 31);
        map.put(3, 31);
        map.put(5, 31);
        map.put(7, 31);
        map.put(8, 31);
        map.put(10, 31);
        map.put(12, 31);
        map.put(4, 30);
        map.put(6, 30);
        map.put(9, 30);
        map.put(11, 30);
        int res = 0;
        if ((a % 4 == 0) && (a % 100 != 0) || (a % 400 == 0)) {
            map.put(2, 29);
        } else {
            map.put(2, 28);
        }
        for (int i = 1; i < b; i++) {
            res += map.get(i);
        }
        System.out.println(res + c);
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
Lorn的意义:你这种岗位在中国现在要么牛马天天加班,要么关系户进去好吃好喝,8年时间,真的天翻地覆了,对于资本来说你就说一头体力更好的牛马,哎,退伍没有包分配你真的亏了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务