java数日子

Problem Description
光阴似箭,日月如梭,大学的时间真是宝贵,要抓紧时间AC^_^。你知道今天是这一年第几天吗,掐指一算还是要算好久,呵呵还是让计算机来做吧。这里的问题就是让你来写一个程序,输入某年某月某日,判断这一天是这一年的第几天?
Input
输入数据有多组,第一行是数据的组数n,下面n行是n组数据,每组数据由3个正整数组成,分别为年、月、日,我们保证每组数据都是有效的日期。
Output
输出所输入的日期是这一年的第几天。
Example Input
2
2009 1 1
2008 1 3
Example Output
1
3
import java.util.Scanner;
public class Main 
{
 public static void main(String[] args) 
 {
  Scanner in=new Scanner(System.in);
  int a;
  int b;
  int c;
  int t;
  t=in.nextInt();
  while(t>0)
  {
   t--;
   a=in.nextInt();
   b=in.nextInt();
   c=in.nextInt();
   int f=0;
   if(b==1)
    System.out.println(c);
   else if(b==2)
    System.out.println(31+c);
   else
   {
    if(a%4==0)
    {
     if(a%100!=0)
     {
      f=1;
     }
     else
     {
      if(a%400==0)
      {
       f=1;
      }
      else f=0;
     }
    }
    else f=0;
   }
   if(f==1)
   {
    switch(b)
    {
    case 3:System.out.println(31+29+c);
    break;
    case 4:System.out.println(31+29+31+c);
    break;
    case 5:System.out.println(31+29+31+30+c);
    break;
    case 6:System.out.println(31+29+31+30+31+c);
    break;
    case 7:System.out.println(31+29+31+30+31+30+c);
    break;
    case 8:System.out.println(31+29+31+30+31+30+31+c);
    break;
    case 9:System.out.println(31+29+31+30+31+30+31+31+c);
    break;
    case 10:System.out.println(31+29+31+30+31+30+31+31+30+c);
    break;
    case 11:System.out.println(31+29+31+30+31+30+31+31+30+31+c);
    break;
    case 12:System.out.println(31+29+31+30+31+30+31+31+30+31+30+c);
    break;
    }
   }
   else
   {
    switch(b)
    {
    case 3:System.out.println(31+28+c);
    break;
    case 4:System.out.println(31+28+31+c);
    break;
    case 5:System.out.println(31+28+31+30+c);
    break;
    case 6:System.out.println(31+28+31+30+31+c);
    break;
    case 7:System.out.println(31+28+31+30+31+30+c);
    break;
    case 8:System.out.println(31+28+31+30+31+30+31+c);
    break;
    case 9:System.out.println(31+28+31+30+31+30+31+31+c);
    break;
    case 10:System.out.println(31+28+31+30+31+30+31+31+30+c);
    break;
    case 11:System.out.println(31+28+31+30+31+30+31+31+30+31+c);
    break;
    case 12:System.out.println(31+28+31+30+31+30+31+31+30+31+30+c);
    break;
    }
   }
  }
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值