题解 | #获得月份天数#
获得月份天数
http://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
int year(y)
{//判断为是否闰年
if ((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0))
return 1;//表明为闰年
else
return 0;//表明为平年
}
int main()
{
int y = 0, m = 0, day = 0;
while (scanf("%d %d", &y, &m) != EOF)
{
if (m == 2)
{
day = year(y) ? 29 : 28;
}
else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
day = 31;
}
else if (m == 4 || m == 6 || m == 9 || m == 11)
{
day = 30;
}
printf("%d\n", day);
}
return 0;
}