a53

Calendar3

a53
Mar 13th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int nr, z, l, a, zile[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  5.  
  6. bool bisect(int x) {
  7. if (x % 4)
  8. return 0;
  9. if (x % 100)
  10. return 1;
  11. if (x % 400)
  12. return 0;
  13. return 1;
  14. }
  15.  
  16. int main() {
  17. cin >> z >> l >> a >> nr;
  18. if (nr > 0) {
  19. while (nr && z > 28) {
  20. z++;
  21. int limit = zile[l];
  22. if (l == 2 && bisect(a) && z > 29)
  23. limit++;
  24. if (z > limit)
  25. l++, z = 1;
  26. if (l > 12)
  27. a++, l = 1;
  28. nr--;
  29. }
  30. while (1) {
  31. int next = 365;
  32. if (l < 3 && bisect(a))
  33. next++;
  34. if (l > 2 && bisect(a+1))
  35. next++;
  36. if (nr < next)
  37. break;
  38. nr -= next;
  39. a++;
  40. }
  41. while (1) {
  42. int next = zile[l];
  43. if (l == 2 && bisect(a))
  44. next++;
  45. if (nr < next)
  46. break;
  47. nr -= next;
  48. l++;
  49. if (l > 12)
  50. a++, l = 1;
  51. }
  52. for (; nr; --nr) {
  53. z++;
  54. int limit = zile[l];
  55. if (l == 2 && bisect(a) && z > 29)
  56. limit++;
  57. if (z > limit)
  58. l++, z = 1;
  59. if (l > 12)
  60. a++, l = 1;
  61. }
  62. }
  63. else {
  64. nr = -nr;
  65. while (nr && z > 28)
  66. z--, nr--;
  67. while (1) {
  68. int next = 365;
  69. if (l > 3 && bisect(a))
  70. next++;
  71. if (l < 2 && bisect(a-1))
  72. next++;
  73. if (nr < next)
  74. break;
  75. nr -= next;
  76. a--;
  77. }
  78. while (1) {
  79. int next = zile[(l+10)%12 + 1];
  80. if (l == 3 && bisect(a))
  81. next++;
  82. if (nr < next)
  83. break;
  84. nr -= next;
  85. l--;
  86. if (!l)
  87. l = 12, a--;
  88. }
  89. for (; nr; --nr) {
  90. z--;
  91. int limit = zile[(l+10)%12 + 1];
  92. if (l == 3 && bisect(a))
  93. limit++;
  94. if (!z)
  95. l--, z = limit;
  96. if (!l)
  97. --a, l = 12;
  98. }
  99. }
  100. cout << z << " " << l << " " << a;
  101. }
Add Comment
Please, Sign In to add comment