题解 | 计算日期到天数转换
计算日期到天数转换
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);
}
}

