USACO 1.1.3 – Friday the Thirteenth



int isLeap(int y) {	return y % 4 == 0 && (y % 100 != 0 || (y % 100 == 0 && y % 400 == 0)); }

int main_friday() {
	ofstream fout("friday.out");
	ifstream fin("friday.in");

	int nm[][12] = { { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
	int sum[8] = { 0};
	int N, d = 0, md = 0, wd = 3, m = 0, y = 1900;
	fin >> N;

	while (y < 1900 + N && ++d && ++md) {
		if (md == 13)
			sum[wd]++;
		if (d == 365 + isLeap(y))
			y++, m = md = d = 0;
		if (md == nm[isLeap(y)][m])
			m++, md = 0;
		wd = (wd % 7) + 1;
	}

	for (int i = 1; i < 7; i++)
		fout << sum[i] << " ";
	fout << sum[7] << endl;
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: