hdu 6112 今夕何夕

三种情况。。。

#include
#include
#include
#include
#include
using namespace std;
int judge(int n)
{
    if(n%4==0)
    {
        if(n%100==0&&n%400!=0)return 365;
        else return 366;
    }
    return 365;
}
int main()
{

    int k;
    scanf("%d",&k);
    while(k--)
    {
        int nian,yue,ri;
        scanf("%d-%d-%d",&nian,&yue,&ri);
        int t=0;
        if(yue>=3)
        {

            do
            {
                nian++;
                t+=judge(nian);
                t%=7;
            }
            while(t);
        }
        else
        {
            if(yue==2&&ri==29)
            {
                do
                {
                    nian++;
                    t+=judge(nian);
                    t%=7;
                    if(t==0&&judge(nian)==366)break;
                }while(1);
            }
            else
            {
                do
                {
                    t+=judge(nian);
                    nian++;
                    t%=7;
                }
                while(t);
            }
        }
        printf("%d\n",nian);

    }
    return 0;
}


/*
10
2017-08-06
2018-08-07
2019-08-06
2020-08-07
2021-08-06
2017-01-07
2018-01-01
2019-01-07
2020-01-01
2020-02-29
*/


你可能感兴趣的:(c++)