package leetcode;
import java.util.Scanner;
/**
-
一年中的第几天 */ public class P1154 { public static void main(String[] args) { //0为平年 1为闰年 int[][] a = {{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; Scanner scanner = new Scanner(System.in); String date = scanner.nextLine(); int year = Integer.parseInt(date.substring(0,4)); //获取年 int month = Integer.parseInt(date.substring(5,7)); //获取月 int day = Integer.parseInt(date.substring(8,10)); //获取日 //判断闰年平年
int switchded = 0;
if (year % 4==0 && year %100 !=0 || year%400==0) {
switchded = 1;
}
//总天数
int sum = 0;
//开始计算
for (int i = 0; i < month-1; i++) {
sum += a[switchded][i];
}
sum+=day;
} }
|