首页 > 编程知识 正文

日期计算器,日期计算天数

时间:2023-05-05 22:45:39 阅读:248381 作者:3278

如题,输入一个日期,格式如:201010 24 ,判断这一天是这一年中的第几天。

输入

第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。

输出

每组输入数据的输出占一行,输出判断出的天数n

样例输入

3

2000 4 5

2001 5 4

2010 10 24

样例输出

96

124

297



public static void main(String[] args){Scanner sc=new Scanner(System.in);int a=sc.nextInt();int[][]i=new int[a][3];for(int b=0;b<a;b++){for(int c=0;c<3;c++){i[b][c]=sc.nextInt();}}int sum = 0;for(int b=0;b<a;b++){for(int c=0;c<2;c++){int feb = 28;if(i[b][0]%4==0 && i[b][0]%100!=0 || i[b][0]%400==0){feb=29;}switch(i[b][1]){case 1 : sum=i[b][2];break;case 2 : sum=31+i[b][2];break;case 3 : sum=31+feb+i[b][2];break;case 4 : sum=31+feb+31+i[b][2];break;case 5 : sum=31+feb+31+30+i[b][2];break;case 6 : sum=31+feb+31+30+31+i[b][2];break;case 7 : sum=31+feb+31+30+31+30+i[b][2];break;case 8 : sum=31+feb+31+30+31+30+31+i[b][2];break;case 9 : sum=31+feb+31+30+31+30+31+31+i[b][2];break;case 10 : sum=31+feb+31+30+31+30+31+31+30+i[b][2];break;case 11 : sum=31+feb+31+30+31+30+31+31+30+31+i[b][2];break;case 12 : sum=31+feb+31+30+31+30+31+31+30+31+30+i[b][2];break;}}System.out.println(sum);}}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。