日期计算
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
1
-
描述
-
如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
-
输入
- 第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。 输出
- 每组输入数据的输出占一行,输出判断出的天数n 样例输入
-
3 2000 4 5 2001 5 4 2010 10 24
样例输出
-
96 124 297
-
import java.util.Scanner; public class Main { public static int f(int year,int month,int day){ int dateSum = 0; for (int i = 1; i < month; i++){ switch(i){ case 1: case 3: case 5: case 7: case 8: case 10: case 12:dateSum += 31; break; case 4: case 6: case 9: case 11:dateSum += 30; break; case 2: if(((year % 4 == 0) & (year % 100 != 0)) | (year % 400 == 0)) dateSum += 29; else dateSum += 28; } } return dateSum = dateSum + day; } public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); while(n>0) { System.out.println(f(s.nextInt(),s.nextInt(),s.nextInt())); n--; } } }