题目:http://acm.hdu.edu.cn/showproblem.php?pid=2005
仅供参考:
#include<stdio.h>
int main()
{
int year, month, day,sum;
while (scanf("%d/%d/%d", &year, &month, &day) != EOF)
{
sum= 0;//每次循环须将sum初始化为0
int m1,m2;
m1 = month / 2;//奇数月数量(不含当前月)
sum+= m1 * 31;
m2 = month - m1-1;//偶数月数量(不含当前月)
if (month > 2)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)//闰年
sum += (m2 - 1) * 30 + 29;
else
sum += (m2 - 1) * 30 + 28;
}
sum += day;//加上当前月份天数
printf("%d\n", sum);
}
return 0;
}
/*
方法二:使用switch case语句,switch(month-1),且去掉break语句
方法三:先将每个月的天数存储在数组a中,执行a[month]=day(当前月份的天数),使用循环计算sum的值
*/