问题 B: Day of Week

本文介绍了一个程序,用于将格里高利历(俄历)的特定日期转换为对应的星期几。程序接收年月日输入,考虑到闰年的规则,并输出对应日期的英文星期名称。示例输入包括2012年12月21日和2013年1月5日,输出分别为Friday和Saturday。

题目描述

We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.

输入

There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.

输出

Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

样例输入

21 December 2012
5 January 2013

样例输出

Friday
Saturday

 

#include <stdio.h>
#include <string.h>
char month[13][20]={
	"",
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
};
char week[7][20]={
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
};

int year[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};

int isLeap(int year){
	return ((year%4==0&&year%100!=0)||year%400==0);
}
struct date{
	int t;
	int y;
	int m;
	int d;
};
int main()
{
	struct date d1,base_date={20130106,2013,1,6};
	char m[20];
	while(scanf("%d %s %d", &d1.d, m, &d1.y)!=EOF){
		int diff=0,sign=-1; 
		struct date d2=base_date;
		for(int i=1;i<=12;i++){
			if(!strcmp(m,month[i])) {d1.m=i;break;}
		}
		d1.t= d1.y*10000 + d1.m*100 + d1.d;
		if(d1.t>d2.t){int tmp; tmp=d1.t; d1.t=d2.t; d2.t=tmp; sign=1;}
		if(d1.t==d2.t){printf("%s\n", week[0]);continue;}
		d1.y=d1.t/10000; d1.m=d1.t%10000/100; d1.d=d1.t%100;
		d2.y=d2.t/10000; d2.m=d2.t%10000/100; d2.d=d2.t%100;
		while(d1.t<d2.t){
			diff++;
			int le=isLeap(d1.y);
			if(d1.m==12 && d1.d==31){d1.y++; d1.m=1;d1.d=1;}
			else if(d1.d == year[le][d1.m]){d1.m++; d1.d=1;}
			else d1.d++;
			d1.t= d1.y*10000 +d1.m*100 +d1.d;
		}
		if(sign>0) printf("%s\n", week[diff%7]);
		if(sign<0) printf("%s\n", week[6-(diff-1)%7]);
	};
	return 0;
}

 

这里面的编码:“ self.node_feat_encoder = nn.Sequential( nn.Linear(time_steps, 16), # 将14个时间步编码为特征 nn.ReLU(), nn.Linear(16, node_feat_dim) )”可以换成正余弦编码吗?数据在输入进去的时候,第一列是时间,请帮我加入正余弦编码:“class TimeCovariates(object): """Extract all time covariates except for holidays.""" def __init__( self, datetimes, normalized = True ): """Init function. Args: datetimes: pandas DatetimeIndex (lowest granularity supported is min) normalized: whether to normalize features or not holiday: fetch holiday features or not Returns: None """ self.normalized = normalized self.dti = datetimes def _minute_of_hour(self): minutes = np.array(self.dti.minute, dtype=np.float32) if self.normalized: minutes = minutes / 59.0 - 0.5 return minutes def _hour_of_day(self): hours = np.array(self.dti.hour, dtype=np.float32) if self.normalized: hours = hours / 23.0 - 0.5 return hours def _day_of_week(self): day_week = np.array(self.dti.dayofweek, dtype=np.float32) if self.normalized: day_week = day_week / 6.0 - 0.5 return day_week def _day_of_month(self): day_month = np.array(self.dti.day, dtype=np.float32) if self.normalized: day_month = day_month / 30.0 - 0.5 return day_month def _day_of_year(self): day_year = np.array(self.dti.dayofyear, dtype=np.float32) if self.normalized: day_year = day_year / 364.0 - 0.5 return day_year def _month_of_year(self): month_year = np.array(self.dti.month, dtype=np.float32) if self.normalized: month_year = month_year / 11.0 - 0.5 return month_year def _week_of_year(self): week_year = np.array(self.dti.strftime("%U").astype(int), dtype=np.float32) if self.normalized: week_year = week_year / 51.0 - 0.5 return week_year def get_covariates(self): """Get all time covariates.""" moh = self._minute_of_hour().reshape(1, -1) hod = self._hour_of_day().reshape(1, -1) dom = self._day_of_month().reshape(1, -1) dow = self._day_of_week().reshape(1, -1) doy = self._day_of_year().reshape(1, -1) moy = self._month_of_year().reshape(1, -1) woy = self._week_of_year().reshape(1, -1) all_covs = [ moh, hod, dom, dow, doy, moy, woy, ] columns = ["moh", "hod", "dom", "dow", "doy", "moy", "woy"] return pd.DataFrame( data=np.vstack(all_covs).transpose(), columns=columns, index=self.dti, )”并帮我分析一下这样是否能够提升预测精度?
04-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值