Created
December 16, 2010 19:41
-
-
Save bobjansen/743874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool checkAddition(int y, int m, int d); | |
bool checkMultiply(int y, int m, int d); | |
bool checkDivision(int y, int m, int d); | |
bool checkSubstraction(int y, int m, int d); | |
bool checkAddition(int y, int m, int d) { | |
return y == m + d; | |
} | |
bool checkSubstraction(int y, int m, int d) { | |
return y == m - d; | |
} | |
bool checkMultiply(int y, int m, int d) { | |
return y == m * d; | |
} | |
bool checkDivision(int y, int m, int d) { | |
return static_cast<float>(y) == static_cast<float>(d) / static_cast<float>(m); | |
} | |
int main() { | |
int special = 0; | |
int extra = 0; | |
int counter = 0; | |
int addCounter = 0; | |
int subCounter = 0; | |
int mulCounter = 0; | |
int divCounter = 0; | |
int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |
for (int y=0; y<100; y++) { | |
if (y%400==0 || (y%100 != 0 && y%4 == 0)) { | |
months[1] = 29; | |
} else { | |
months[1] = 28; | |
} | |
for (int m=1; m<=12; m++) { | |
for (int d=1; d<=months[m-1]; d++) { | |
extra = 0; | |
if (checkAddition(y, m, d)) { | |
cout << "Add: " << d << "-" << m << "-" << y << " "; | |
addCounter++; | |
extra++; | |
} | |
if (checkSubstraction(y, m, d)) { | |
cout << "Sub: " << d << "-" << m << "-" << y << " "; | |
subCounter++; | |
extra++; | |
} | |
if (checkMultiply(y, m, d)) { | |
cout << "Mul: " << d << "-" << m << "-" << y << " "; | |
mulCounter++; | |
extra++; | |
} | |
if (checkDivision(y, m, d)) { | |
cout << "Div: " << d << "-" << m << "-" << y; | |
divCounter++; | |
extra++; | |
} | |
if (extra > 1) | |
special++; | |
if (extra > 0) { | |
counter++; | |
cout << endl; | |
} | |
} | |
} | |
} | |
cout << "Adds: " << addCounter << endl; | |
cout << "Subs: " << subCounter << endl; | |
cout << "Mults: " << mulCounter << endl; | |
cout << "Divs: " << divCounter << endl; | |
cout << "Number of magic dates: " << counter << endl; | |
if (special > 0) | |
cout << "Some dates are extra special!" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment