- 輸入
- 第一行輸入一個數N(0<N<=100),表示有N組測試數據。後面的N行輸入多組輸入數據,每行的輸入數據都是一個按題目要求格式輸入的日期。
- 輸出
- 每組輸入數據的輸出佔一行,輸出判斷出的天數n
- 樣例輸入
-
3 2000 4 5 2001 5 4 2010 10 24
- 樣例輸出
-
96 124
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); } } }
日期計算
描述
如題,輸入一個日期,格式如:2010 10 24 ,判斷這一天是這一年中的第幾天。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.