获得月份天数

获得月份天数

http://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6

#include <stdio.h>
int main()
{
    int year = 0;
    int month = 0;
    int num1[7] = { 1,3,5,7,8,10,12 };
    int num2[4] = { 4,6,9,11 };
    while (scanf("%d %d", &year, &month) != EOF)
    {
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        {
            if (month == 2)
            {
                printf("29\n");
            }
            else
            {
                for (int i = 0; i < 7; i++)
                {
                    if (month == num1[i])
                    {
                        printf("31\n");
                    }
                }
                for (int j = 0; j < 4; j++)
                {
                    if (month == num2[j])
                    {
                        printf("30\n");
                    }
                }
            }
        }
        else if (month == 2)
        {
            printf("28\n");
        }
        else
        {
            for (int i = 0; i < 7; i++)
            {
                if (month == num1[i])
                {
                    printf("31\n");
                }
            }
            for (int j = 0; j < 4; j++)
            {
                if (month == num2[j])
                {
                    printf("30\n");
                }
            }
        }

    }

    return 0;
}
全部评论

相关推荐

扭转乾坤_:现在企业都是学华为,一直通过丢池子里,最后捞
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务