C++ 三天打鱼两天晒网。C++

#include


int Month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

int isLeap(int year) {
    return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}

int getDaysByM(int year,int month) {
    int days = Month[month];
    if (isLeap(year) && month == 2)
        days += 1;
    return days;
}
 

int main()
{
    int year, month, day;
    while (scanf("%d-%d-%d", &year, &month, &day) != EOF) {
        int days = 0;
        int y = 2000, m = 1, d = 1;
        while (1) {
            if (y == year && month == m && day == d)
                break;

            if (y < year) {
                y += 1;
                if (isLeap(y)) {
                    days += 366;                      
                }
                else {
                    days += 365;                       
                }
            }
            else {
                d += 1;
                days += 1;
                if (d > getDaysByM(y, m)) {
                    m += 1;
                    d = 1;
                    if (m > 12) {
                        m = 1;
                        y += 1;
                    }                              
                }
            }
            
        }
        int res = days % 5;
        if (res < 3) {
            puts("打鱼");
        }
        else {
            puts("晒网");
        }

    }
}

你可能感兴趣的:(java,算法,数据结构)