Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long int
  5.  
  6. int month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  7. int leap_month[]= {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  8.  
  9. struct node
  10. {
  11. ll x;
  12. int pos;
  13. };
  14.  
  15. bool cmp(node a,node b)
  16. {
  17. return a.x<b.x;
  18. }
  19.  
  20. ll no_of_leap(ll x)
  21. {
  22. ll a=x/4;
  23. ll b=x/100;
  24. ll c=x/400;
  25. return a-b+c;
  26. }
  27.  
  28. bool isLeap(ll x)
  29. {
  30. if(x%400==0)
  31. return 1;
  32. if(x%100==0)
  33. return 0;
  34. if(x%4==0)
  35. return 1;
  36. return 0;
  37. }
  38.  
  39. int main()
  40. {
  41. ll a,b,c,d,cur,future,p,q,r,s,days,gap;
  42. while(cin>>a>>b>>c>>d)
  43. {
  44. if(a==0)
  45. break;
  46. cur=(d-1)*365+no_of_leap(d-1);
  47. for(int i=0; i<c-1; i++)
  48. {
  49. cur=cur+month[i];
  50. }
  51. if(isLeap(d)&&c>2)
  52. cur++;
  53. cur+=b;
  54. future=cur+a;
  55. ll low=future/366;
  56. ll high=future/365,mid;
  57. if(future%365)
  58. high++;
  59. while(1)
  60. {
  61. mid=(low+high)>>1;
  62. days=(mid-1)*365;
  63. days+=no_of_leap(mid-1);
  64. gap=future-days;
  65. if(isLeap(mid)&&gap>0&&gap<=366)
  66. {
  67. for(int i=0; i<12; i++)
  68. {
  69. if(gap-leap_month[i]<=0)
  70. {
  71. cout<<gap<<" "<<i+1<<" "<<mid<<endl;
  72. break;
  73. }
  74. gap-=leap_month[i];
  75. }
  76. break;
  77. }
  78. else if(gap>0&&gap<=365)
  79. {
  80. for(int i=0; i<12; i++)
  81. {
  82. if(gap-month[i]<=0)
  83. {
  84. cout<<gap<<" "<<i+1<<" "<<mid<<endl;
  85. break;
  86. }
  87. gap-=month[i];
  88. }
  89. break;
  90. }
  91. if(gap>0)
  92. low=mid+1;
  93. else
  94. high=mid-1;
  95. }
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement