Untitled
raw download clone
CPP
views 17
,
size 2603 b
#include<bits/stdc++.h>
using namespace std;
typedef long long          ll;
typedef vector<int>        vi;
typedef pair<int, int>     ii;
typedef vector<ii>         vii;
typedef set<int>           si;
typedef map<string, int>   msi;
typedef map<int, int>      mii;
typedef map<int, bool>     mib;
#define MOD 1000000007
#define MX 1000000
#define forr(a,b)          for(int i=a; i<=b; i++)
#define rforr(a,b)         for(int i=b; i>=a; i--)
#define sf(a)              scanf("%d",&a)
#define sf2(a,b)           scanf("%d%d",&a,&b)
#define sf3(a,b,c)         scanf("%d%d%d",&a,&b,&c)
#define sfl(a)             scanf("%lld",&a)
#define sfl2(a,b)          scanf("%lld%lld",&a,&b)
#define pf(a)              printf("%d\n",a)
#define pf2(a,b)           printf("%d %d\n",a,b)
#define pf3(a,b,c)         printf("%d%d%d\n",a,b,c)
#define pfl(a)             printf("%lld\n",a)
#define pfl2(a,b)          printf("%lld%lld",a,b)
#define pb                 push_back
#define ppb                pop_back
#define ms(a,v)            memset(a, v, sizeof a)
#define mp                 make_pair
bool is_leap(int yr)
{
    if(yr%400==0 || yr%4==0&&yr%100!=0) return 1;
    return 0;
}
int num_of_ly_upto(int yr)
{
    int ret=yr/4;
    ret-=yr/100;
    ret+=yr/400;
    return ret;
}
int main()
{
    printf("birth day: ");
    int bd;
    sf(bd);
    printf("birth month: ");
    int bm;
    sf(bm);
    printf("birth yr: ");
    int by;
    sf(by);
    printf("curr day: ");
    int cd;
    sf(cd);
    printf("curr month: ");
    int cm;
    sf(cm);
    printf("curr yr: ");
    int cy;
    sf(cy);
    int ans=0;
    //brh day d.m.y format a ase
    //brth day 1.1.y format a an ejonno ans- kora lgbe
    while(bd!=1){
        ans--;
        bd--;
    }
    //brt day 1.m.y format a ase
    while(bm!=1){
        bm--;
        if(bm==1||bm==3||bm==5||bm==7||bm==8||bm==10) ans-=31;
        else if(bm==2 && is_leap(by)) ans-=29;
        else if(bm==2 && !is_leap(by)) ans-=28;
        else ans-=30;
    }
    //curr day 1.1.y format a an ebr ans+ hbe
    while(cd!=1){
        ans++;
        cd--;
    }
    while(cm!=1){
        cm--;
        if(cm==1||cm==3||cm==5||cm==7||cm==8||cm==10) ans+=31;
        else if(cm==2 && is_leap(cy)) ans+=29;
        else if(cm==2 && !is_leap(cy)) ans+=28;
        else ans+=30;
    }
    // by ar cy er moddhe kyta lpyr ase
    int lyn= num_of_ly_upto(cy-1) - num_of_ly_upto(by-1);
    //egla ans+ hbe
    ans+=lyn;
    //baki yr*365 + hbe
    ans+= (cy-by)*365;
    pf(ans);
}
close fullscreen
Login or Register to edit or fork this paste. It's free.