日期计算

来源:互联网 发布:苹果手机 解压缩软件 编辑:程序博客网 时间:2024/05/22 05:17
描述
如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
输入
第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。
输出
每组输入数据的输出占一行,输出判断出的天数n
样例输入
32000 4 52001 5 42010 10 24
样例输出
96124

297

import java.util.*;public class Main { public static void main(String[] args) {  Scanner in=new Scanner(System.in);  int k=in.nextInt();       while(k-->0){          int y=in.nextInt(),m=in.nextInt(),d=in.nextInt();          int[][] cal={{0,31,29,31,30,31,30,31,31,30,31,30,31},               {0,31,28,31,30,31,30,31,31,30,31,30,31}};      int cnt=0;      if(y%4==0&&y%100!=0||y%400==0){      for (int i = 1; i<=m-1; i++)  cnt+=cal[0][i];      cnt+=d;      }      else{      for (int i = 1; i<=m-1; i++)  cnt+=cal[1][i];      cnt+=d;      }        System.out.println(cnt);              }   } }