Top

O(1)判星期几


1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Change(int year,int month,int day)//根据日期判断出星期几
{
if(month==1||month==2)
{
month+=12;
year--;
}
int c=year/100;
int y=year%100;
int m=month;
int d=day;
int W=c/4-2*c+y+y/4+26*(m+1)/10+d-1; if(W<0) return (W+(-W/7+1)*7)%7;
return W%7;
}
文章版权为Anoyer博客所有,转载请以链接形式标明本文地址