主要是判断闰年,闰年的2月有29天,平年的2月有28天。
运行时间:16ms超过92.17% 用Java提交的代码 占用内存:9624KB超过94.29%用Java提交的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static int[] days = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String[] s1 = s.split(" ");
int year = Integer.parseInt(s1[0]);
int month = Integer.parseInt(s1[1]);
int day = Integer.parseInt(s1[2]);
days[1] = getFebrurayDays(year);
int sum = 0;
for (int i = 0; i < month - 1; i++) {
sum = sum + days[i];
}
sum = sum + day;
System.out.println(sum);
}
public static int getFebrurayDays(int year) {
if (year % 4 == 0 && year % 100 != 0) {
return 29;
} else if (year % 400 == 0) {
return 29;
}
return 28;
}
}

京公网安备 11010502036488号