USACO-Section1.1 Friday the Thirteenth

##Friday the Thirteenth##
本题主要内容是根据所给日期,计算星期几,再简化,就是计算两个日期间的间隔,这时用儒略日计算就比较方便。儒略日的计算方法可另行查找。
代码如下:

/*
ID: xhzdcyy1
PROB: friday
LANG: C++         
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
	ofstream fout ("friday.out");
    ifstream fin ("friday.in");
	int n;
	fin>>n;
	int arr[7]={0};
	int jd;
	int y,m,day,a,year,month;
	year=1900;
	month=1;
	day=13;
	while(year<1900+n){
		a=(14-month)/12;
		y=year+4800-a;
		m=month+12*a-3;
		jd=(153*m+2)/5+365*y+y/4-y/100+y/400+day-32045;
		++arr[(jd+2)%7];
		if(month==12){
			month=1;
			++year;
		}
		else{
			++month;
		}
	}
	for(int i=0;i<7;i++){
		fout<<arr[i];
		if(i!=6) fout<<" ";
	}
	fout<<endl;
 	return 0;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值