- 題目描述:
-
輸入年、月、日,計算該天是本年的第幾天。
- 輸入:
-
包括三個整數年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
- 輸出:
-
輸入可能有多組測試數據,對於每一組測試數據,輸出一個整數,代表Input中的年、月、日對應本年的第幾天。
- 樣例輸入:
-
1990 9 20 2000 5 1
- 樣例輸出:
-
263 122
- 來源:
題目分析:
源代碼
#include <stdio.h>
#include <stdlib.h>
int leap(int year)
{
if((year%4==0 && year%100!=0) || year%400==0)
return 1;
else
return 0;
}
int main()
{
int month[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int y, m, d;
while(scanf("%d%d%d", &y, &m, &d) != EOF)
{
int sum = 0;
int i;
for(i = 1; i < m; i++)
sum += month[leap(y)][i];
sum += d;
printf("%d\n", sum);
}
//system("pause");
return 0;
}
/**************************************************************
Problem: 1070
User: superlc320
Language: C++
Result: Accepted
Time:10 ms
Memory:1020 kb
****************************************************************/