java數日子

來源:互聯網
上載者:User
Problem Description 光陰似箭,日月如梭,大學的時間真是寶貴,要抓緊時間AC^_^。你知道今天是這一年第幾天嗎,掐指一算還是要算好久,呵呵還是讓電腦來做吧。這裡的問題就是讓你來寫一個程式,輸入某年某月某日,判斷這一天是這一年的第幾天。 Input 輸入資料有多組,第一行是資料的組數n,下面n行是n組資料,每組資料由3個正整數組成,分別為年、月、日,我們保證每組資料都是有效日期。 Output 輸出所輸入的日期是這一年的第幾天。 Example Input
22009 1 12008 1 3
Example Output
13
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;    }   }  }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.