杭电2005
1个回答
展开全部
//******************************************************************************
// 杭电2005 第几天? 代码已AC 可参考
//******************************************************************************
#include<stdio.h>
int main()
{
int i, n, year, moth, day, a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
while(scanf("%d/%d/%d", &year, &moth, &day) != EOF)
{
if (moth > 2 && ((year % 400 == 0) || (year % 100 != 0) && (year % 4 == 0)))
day += 1; //闰年且月份大于2时,天数加一
for(n = i = 0; i < moth - 1; i++) //累加天数
n += a[i];
printf("%d\n", n + day); //加上最后一个月的天数并输出
}
}
// 杭电2005 第几天? 代码已AC 可参考
//******************************************************************************
#include<stdio.h>
int main()
{
int i, n, year, moth, day, a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
while(scanf("%d/%d/%d", &year, &moth, &day) != EOF)
{
if (moth > 2 && ((year % 400 == 0) || (year % 100 != 0) && (year % 4 == 0)))
day += 1; //闰年且月份大于2时,天数加一
for(n = i = 0; i < moth - 1; i++) //累加天数
n += a[i];
printf("%d\n", n + day); //加上最后一个月的天数并输出
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询