Project Euler Homework

019.cpp

Go to the documentation of this file.
00001 
00017 #include <iostream>
00018 using namespace std;
00019 
00045 unsigned short
00046 weekday (int DD, int MM, int YYYY)
00047 {
00048 //Jan & Feb are counted as month 13 & 14 of the prevoius year
00049   if (MM <= 2)
00050     {
00051       MM += 12;
00052       YYYY--;
00053     }
00054   return
00055     (YYYY + YYYY / 4 + (YYYY / 100) * 6 + YYYY / 400 + 26 * (MM + 1) / 10 +
00056      DD - 1) % 7;
00057 }
00058 
00059 int
00060 main ()
00061 {
00062   unsigned count = 0;
00063   for (int yyyy = 1901; yyyy <= 2000; yyyy++)
00064     for (int mm = 1; mm <= 12; mm++)
00065       if (weekday (1, mm, yyyy) == 0)   //Sunday
00066         {
00067           count++;
00068           //cout << mm <<'/'<<yyyy<<endl;
00069         }
00070   cout << count << endl;
00071   return 0;
00072 }
00073 
 All Classes Files Functions Variables