HDU 1201(水题)

题意:如题。

 

#include 
#include 

int all[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };

struct Date
{
    int year, month, day;
    Date() {}
    Date(int y, int m, int d) : year(y), month(m), day(d) {}
    bool isLeap(int _year)
    {
        return (_year % 4 == 0 && _year % 100 != 0) || _year % 400 == 0;
    }
    int getDay()
    {
        bool t;
        if (!(t = isLeap(year + 18)) && month == 2 && day == 29) return -1;
        int sum = 17 * 365;
        for (int i = 1; i < 18; ++i)
            if (isLeap(year + i)) ++sum;
        sum += all[month-1];
        if (t && month > 2) ++sum;
        sum += day;
        sum += 365 - all[month-1];
        if (month - 1 < 2 && isLeap(year))
            ++sum;
        sum -= day;
        return sum;
    }
};


int main()
{
    int T;
    Date d;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d-%d-%d", &d.year, &d.month, &d.day);
        printf("%d\n", d.getDay());
    }
}


 

你可能感兴趣的:(水题&模拟&规律)