USACO 1.1 Friday the Thirteenth

此题大致思路就是计算出到每月13号时的总天数sum_day,再让sum_day%7就可以了。 但是一定注意题目中的细节,因为最后又加了一次12月份,就会超出给定的时间段,不要忘了将其减去,我第一次时就忘了。 对于这种题目新手一定自己动手写代码,编码力提高才会快。
请看上海交大ACM队长对于编码能力的总结

/*
	ID: acmerfi1
	PROG: friday
	LANG: C++
*/
#include <stdio.h>
#include <string.h>

int sum[8], sum_year, sum_day;
int month1[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month2[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int isleap(int year)
{
	if((0 == year%4 && year % 100 != 0) || 0 == year % 400)
	{
		return 1;
	}
	else return 0;
}

int main()
{
	freopen("friday.in", "r", stdin);
	freopen("friday.out", "w", stdout);
	scanf("%d", &sum_year);
	memset(sum, 0, sizeof(sum));
	sum_day = 13;
	sum[sum_day % 7]++;
	for(int i = 1900; i <= 1900 + sum_year - 1; i++)
	{
		for(int j = 0; j < 12; j++)
		{
			if(isleap(i))
			{
				sum_day += month2[j];
				sum[sum_day % 7]++;
			} 
			else 
			{
				sum_day += month1[j];
				sum[sum_day % 7]++;
			}
		}	
	}
	sum[sum_day % 7]--;	 // 犯错一次 
	printf("%d %d %d %d %d %d %d\n", sum[6], sum[0], sum[1], sum[2], sum[3], sum[4], sum[5]);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值