1.1.3 Friday the Thirteenth
/*
ID: vijay.i2
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool leapYear(int n){
if(n % 400 == 0)
return true;
else if(n % 100 == 0)
return false;
else if(n % 4 == 0)
return true;
else
return false;
}
int main() {
ofstream fout ("friday.out");
ifstream fin ("friday.in");
int n;
fin >> n;
int week[7] = {0};
int days = 0, currentDay = 4;
int months[12] = {31, 31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30};
for(int i=1900; i<=1900+n-1; i++){
if(leapYear(i))
months[2] = 29;
else
months[2] = 28;
for(int j=0; j<12; j++){
days = months[j];
currentDay += days % 7;
if(currentDay > 6)
currentDay -= 7;
week[currentDay]++;
}
}
for(int i=0; i<7; i++)
if(i <= 5)
fout << week[i] << " ";
else
fout << week[i] << endl;
return 0;
}
/*
http://ideone.com/RvRq8S
http://train.usaco.org/usacoprob2?a=id79oFP6BDM&S=friday
*/
#include <iostream>
using namespace std;
bool leapYear(int n){
if(n % 400 == 0)
return true;
else if(n % 100 == 0)
return false;
else if(n % 4 == 0)
return true;
else
return false;
}
int main() {
int n;
cin >> n;
int week[7] = {0};
int days = 0, currentDay = 4;
int months[12] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
for(int i=1900; i<=1900+n-1; i++){
if(leapYear(i))
months[2] = 29;
else
months[2] = 28;
for(int j=0; j<12; j++){
days = months[j];
currentDay += days % 7;
if(currentDay > 6)
currentDay -= 7;
week[currentDay]++;
}
}
for(int i=0; i<7; i++)
if(i <= 5)
cout << week[i] << " ";
else
cout << week[i] << endl;
return 0;
}