【水题】USACO Friday the Thirteenth

进入USACO要注册才可看题: http://train.usaco.org/usacogate

题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/13%5C303.asp

SAMPLE INPUT (file friday.in)
20
SAMPLE OUTPUT (file friday.out)
36 33 34 33 35 35 34



历法中的水题,不多说……

/*
ID: 1006100071
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
//#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;

int year[405];    //year[i]表示前i年有多少天
int month[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

inline bool isleap (int y)
{
	if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
		return true;
	return false;
}
inline int days (int y, int m)
{
	int j, day = year[y];
	for (j = 1; j < m; j++)
	{
		if (j == 2 && !isleap (1900+y))
			day += 28;
		else day += month[j];
	}
	day += 13;
	return day;
}
int main()
{
	/*freopen ("friday.in", "r", stdin);
	freopen ("friday.out", "w", stdout);*/
	int i, j, n, ans[10] = {0};
	for (i = 1; i <= 405; i++)
	{
		if (isleap (1900+i-1))
			year[i] = year[i-1] + 366;
		else year[i] = year[i-1] + 365;
	}
	scanf ("%d", &n);
	for (i = 0; i < n; i++)
	{
		for (j = 1; j < 13; j++)
			ans[days(i, j)%7]++;
	}
	printf ("%d %d", ans[6], ans[0]);
	for (i = 1; i < 6; i++)
		printf (" %d", ans[i]);
	printf ("\n");
}

你可能感兴趣的:(C++,c,算法,编程语言,ACM)