1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
//counts the number of days the date 13 appears from jan 1, 1900 to dec 31, 1900+N-1, N is the only input
//jan 1, 1900 was a monday
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//{1=31, 2=28, 3=31, 4=30, 5=31, 6=30, 7=31, 8=31, 9=30, 10=31, 11=30, 12=31}
int main()
{
ifstream in("friday.txt");
ofstream out("friday.out");
/*int saturday =0;
int sunday =0;
int monday =0;
int tuesday =0;
int wednesday =0;
int thursday =0;
int friday =0;*/
//used for counting the number of times each day in on the 13th
int dayname[7] ={0, 0, 0, 0, 0, 0, 0};
string day[7] = {"saturday", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday"};
//starts on monday
int current =2;
//string current_day = day[current];
int N;
//in >> N;
N=20;
int days;
for(int y=1900;y<=(1900+N-1); y++)
{
for(int m=1; m <= 12; m++)
{
switch(m)
{
case 1: days =31;
case 2:
if(y%4 ==0 && y%100 != 0)
days =29;
else if(y%100 ==0 && y%400 ==0)
days =29;
else
days=28;
case 3: days =31;
case 4: days =30;
case 5: days =31;
case 6: days =30;
case 7: days =31;
case 8: days =31;
case 9: days =30;
case 10: days =31;
case 11: days =30;
case 12: days =31;
}
for(int d=1; d<=days; d++)
{
//current_day = day[current];
if(d ==13)
{
dayname[current]++;
}
if(current ==6)
current =0;
else
current++;
}//day loop
}//month loop
} //year loop
for(int t=0; t<7; t++)
{
cout << dayname[t] << endl;
}
in.close();
out.close();
return(0);
}
|