日期計算
日期計算時間限製:3000 ms | 內存限製:65535 KB
難度:1
描述
如題,輸入一個日期,格式如:2010 10 24 ,判斷這一天是這一年中的第幾天。
輸入
第一行輸入一個數N(0<N<=100),表示有N組測試數據。後麵的N行輸入多組輸入數據,每行的輸入數據都是一個按題目要求格式輸入的日期。
輸出
每組輸入數據的輸出占一行,輸出判斷出的天數n
樣例輸入
3
2000 4 5
2001 5 4
2010 10 24
樣例輸出
96
124
297
code:
01.#include <iostream>02. 03.using
namespace std;04. 05.int
main()06.{07.int
nTestNum;08.int
nYear,09.nMonth,10.nDay;11. 12.cin >> nTestNum;13.while
(nTestNum--)14.{15.cin >> nYear >> nMonth >> nDay;16.while
(nMonth >= 1)17.{18.switch
(--nMonth)19.{20.case
1: case
3: case 5: case
7:21.case
8: case
10: case 12:22.nDay += 31;23.break;24.case
4: case
6: case 9: case
11:25.nDay += 30;26.break;27.case
2:28.if
((nYear % 4 == 0 && nYear % 100) || nYear % 400 == 0)//if is a leap year29.nDay += 29;30.else31.nDay += 28;32.break;33.}34.}35.cout << nDay << endl;36.}37.return
0;38.}
最後更新:2017-04-02 15:14:52