Untitled

 avatar
user_0483151
plain_text
5 months ago
1.6 kB
2
Indexable
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)

using namespace std;

int day_of_month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int dd,mm,yy,ye;

bool nhuan(int nam)
{
    return ( nam % 400 == 0 || (nam % 100 != 0 && nam % 4 == 0));
}

int sonhuan(int nam)
{
    return ( nam/4 - nam/100 + nam/400);
}

int number_of_day ( int ngay, int thang, int nam)
{
    int songay = (nam - 1) * 365 + sonhuan(nam -1);
    FOR(i,1,thang-1) songay += day_of_month[i];
    if (nhuan(nam) && thang > 2) songay ++;
    songay += ngay;
    return songay;
}

void tinh_ngay_thang_nam ( int songay, int &ngay, int &thang, int &nam)
{
    nam = songay / 366;
    while (nam * 365 + sonhuan(nam) < songay) nam++;
    songay -= ((nam-1) * 365 + sonhuan(nam-1));

    int day_o[13];
    FOR(i,1,12) day_o[i] = day_of_month[i];
    if (nhuan(nam)) day_o[2] ++;
    thang = 1;
    while ( songay > day_o[thang])
    {
        songay -= day_o[thang];
        thang ++;
    }
    ngay = songay;
}

bool ngayhan(int u)
{
    int p = 0;
    if (u % 23 == 0) p ++;
    if (u % 27 == 0) p ++;
    if (u % 33 == 0) p ++;
    return (p == 2);
}

void xuli()
{
    bool ok =true;
    int ngay, thang, nam;
    int moc = number_of_day(dd,mm,yy);
    int xp = number_of_day(1,1,ye);
    int kt = number_of_day(31,12,ye);
    FOR(i,xp,kt)
        if (ngayhan(i - moc))
        {
            ok = false;
            tinh_ngay_thang_nam(i,ngay,thang,nam);
            cout << ngay << " " << thang << " " << nam << endl;
        }
    if (ok) cout<<"lucky";
}

int main()
{
    cin >> dd >> mm >> yy >> ye;
    xuli();
    return 0;
}
Leave a Comment