Advertisement
angryatti

Mikor lesz húsvét?

Jan 27th, 2022
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1.     #include <sstream>
  2.     #include <iostream>
  3.     using namespace std;
  4.     string ZeroPadNumber(int num){
  5.         stringstream ss;
  6.         // the number is converted to string with the help of stringstream
  7.         ss << num;
  8.         string ret;
  9.         ss >> ret;
  10.         // Append zero chars
  11.         int str_length = ret.length();
  12.         for (int i = 0; i < 2 - str_length; i++)
  13.             ret = "0" + ret;
  14.         return ret;
  15.         }
  16.     void EasterDate(int X){                             // X = year to compute
  17.         int K, M, S, A, D, R, OG, SZ, OE;
  18.         K  = X / 100;                                   // Secular number
  19.         M  = 15 + (3 * K + 3) / 4 - (8 * K + 13) / 25;  // Secular Moon shift
  20.         S  = 2 - (3 * K + 3) / 4;                       // Secular sun shift
  21.         A  = X % 19;                                    // Moon parameter
  22.         D  = (19 * A + M) % 30;                         // Seed for 1st full Moon in spring
  23.         R  = D / 29 + (D / 28 - D / 29) * (A / 11);     // Calendarian correction quantity
  24.         OG = 21 + D - R;                                // Easter limit
  25.         SZ = 7 - (X + X / 4 + S) % 7;                   // 1st sunday in March
  26.         OE = 7 - (OG - SZ) % 7;                         // Distance Easter sunday from Easter limit in days
  27.         //Easter = DateSerial(X, 3, OG + OE);           // Result: Easter sunday as number of days in March
  28.         cout << X << "-" << ZeroPadNumber(((OG + OE)>31)?4:3) << "-" << ZeroPadNumber((((OG + OE)%31)==0)?31:((OG + OE)%31));
  29.         }
  30.     int main ()
  31.     {
  32.         int year;
  33.         do {
  34.             cout << "Put the year: ";
  35.             cin >> year;
  36.             EasterDate(year);
  37.             cout << endl << endl;
  38.             }
  39.         while (year>0);
  40.         return 0;
  41.     }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement