gatto blogja (Official)

Tudomány
gatto•  2016. április 1. 09:42

Húsvét mint internacionálé



programkód (C++): nagy nehezen vadásztam egy világból... a technológiából.

  1.    #include <sstream>    #include <iostream>

  2.     using namespace std;
  3.     string ZeroPadNumber(int num){
  4.         stringstream ss;
  5.         // the number is converted to string with the help of stringstream
  6.         ss << num;
  7.         string ret;
  8.         ss >> ret;
  9.         // Append zero chars
  10.         int str_length = ret.length();
  11.         for (int i = 0; i < 2 - str_length; i++)
  12.             ret = "0" + ret;
  13.         return ret;
  14.         }
  15.     void EasterDate(int X){                             // X = year to compute
  16.         int K, M, S, A, D, R, OG, SZ, OE;
  17.         K  = X / 100;                                   // Secular number
  18.         M  = 15 + (3 * K + 3) / 4 - (8 * K + 13) / 25;  // Secular Moon shift
  19.         S  = 2 - (3 * K + 3) / 4;                       // Secular sun shift
  20.         A  = X % 19;                                    // Moon parameter
  21.         D  = (19 * A + M) % 30;                         // Seed for 1st full Moon in spring
  22.         R  = D / 29 + (D / 28 - D / 29) * (A / 11);     // Calendarian correction quantity
  23.         OG = 21 + D - R;                                // Easter limit
  24.         SZ = 7 - (X + X / 4 + S) % 7;                   // 1st sunday in March
  25.         OE = 7 - (OG - SZ) % 7;                         // Distance Easter sunday from Easter limit in days
  26.         //Easter = DateSerial(X, 3, OG + OE);           // Result: Easter sunday as number of days in March
  27.         cout << X << "-" << ZeroPadNumber(((OG + OE)>31)?4:3) << "-" << ZeroPadNumber((((OG + OE)%31)==0)?31:((OG + OE)%31));
  28.         }
  29.     int main ()
  30.     {
  31.         int year;
  32.         do {
  33.             cout << "Put the year: ";
  34.             cin >> year;
  35.             EasterDate(year);
  36.             cout << endl << endl;
  37.             }
  38.         while (year>0);
  39.         return 0;

szerk:2016.04.10.