Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- int leap_month[]= {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- struct node
- {
- ll x;
- int pos;
- };
- bool cmp(node a,node b)
- {
- return a.x<b.x;
- }
- ll no_of_leap(ll x)
- {
- ll a=x/4;
- ll b=x/100;
- ll c=x/400;
- return a-b+c;
- }
- bool isLeap(ll x)
- {
- if(x%400==0)
- return 1;
- if(x%100==0)
- return 0;
- if(x%4==0)
- return 1;
- return 0;
- }
- int main()
- {
- ll a,b,c,d,cur,future,p,q,r,s,days,gap;
- while(cin>>a>>b>>c>>d)
- {
- if(a==0)
- break;
- cur=(d-1)*365+no_of_leap(d-1);
- for(int i=0; i<c-1; i++)
- {
- cur=cur+month[i];
- }
- if(isLeap(d)&&c>2)
- cur++;
- cur+=b;
- future=cur+a;
- ll low=future/366;
- ll high=future/365,mid;
- if(future%365)
- high++;
- while(1)
- {
- mid=(low+high)>>1;
- days=(mid-1)*365;
- days+=no_of_leap(mid-1);
- gap=future-days;
- if(isLeap(mid)&&gap>0&&gap<=366)
- {
- for(int i=0; i<12; i++)
- {
- if(gap-leap_month[i]<=0)
- {
- cout<<gap<<" "<<i+1<<" "<<mid<<endl;
- break;
- }
- gap-=leap_month[i];
- }
- break;
- }
- else if(gap>0&&gap<=365)
- {
- for(int i=0; i<12; i++)
- {
- if(gap-month[i]<=0)
- {
- cout<<gap<<" "<<i+1<<" "<<mid<<endl;
- break;
- }
- gap-=month[i];
- }
- break;
- }
- if(gap>0)
- low=mid+1;
- else
- high=mid-1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement