fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. long julianDate(int y, int m, int d)
  7. {
  8. if (m <= 2) {
  9. y--;
  10. m += 12;
  11. };
  12. long A = y/100;
  13. A = 2 - A + A/4;
  14. long J = (1461L * y)/ 4;
  15. long K = (306001L*(m + 1))/10000L;
  16. return J + K + d + 1720995L + A;
  17. };
  18.  
  19. void grigorianDate(long JD,
  20. int& y, int& m, int& d)
  21. {
  22. long A = (JD*4 - 7468865L)/146097L;
  23. A = JD + 1 + A - (A/4L);
  24. long B = A + 1524;
  25. long C = (B*20L - 2442L)/7305L;
  26. long D = (C * 1461L) / 4L;
  27. long E = (10000L * (B-D)) / 306001L;
  28. d = B - D - E*306001L/10000L;
  29. m = ( E <= 13 ) ? E - 1 : E - 13;
  30. y = ( m > 2 ) ? C - 4716 : C - 4715;
  31. };
  32.  
  33. int weekday(long jd) { return (jd+1)%7; }
  34.  
  35. int main()
  36. {
  37. int cnt[7] {0};
  38. for(int y = 1900; y < 2300; ++y)
  39. for(int m = 1; m <= 12; ++m)
  40. cnt[weekday(julianDate(y,m,13))]++;
  41.  
  42. cout << "13:\n";
  43. cout << "sunday: " << cnt[0] << " times\n";
  44. cout << "monday: " << cnt[1] << " times\n";
  45. cout << "tuesday: " << cnt[2] << " times\n";
  46. cout << "wednesday: " << cnt[3] << " times\n";
  47. cout << "thursday: " << cnt[4] << " times\n";
  48. cout << "friday: " << cnt[5] << " times\n";
  49. cout << "saturday: " << cnt[6] << " times\n";
  50.  
  51. }
  52.  
Success #stdin #stdout 0.01s 5448KB
stdin
Standard input is empty
stdout
13:
sunday:    687 times
monday:    685 times
tuesday:   685 times
wednesday: 687 times
thursday:  684 times
friday:    688 times
saturday:  684 times