unsigned char CalcWeekDay (unsigned char century, unsigned char year, unsigned char month ,unsigned char day ) { if ( month <= 2) { month +=12 ;//今年的 1月 2月是去年的“13月14月” year--;//注意“去年”2字 if (year >= 99) {//年为无符号变量 year = 99;//原年必为0 century--;//世纪也需-1 } } return ( (century%4*5 + year + year /4 + ( 13 * month - 27 ) / 5 + day)% 7 ); } 或 unsigned char CalcWeekDay (unsigned char century, unsigned char year, unsigned char month ,unsigned char day ) { if ( month <= 2) { month |=4 ;//今年的 1月 2月是也是去年的“5月6月”的月表 year--;//注意“去年”2字 if (year >= 99) {//年为无符号变量 year = 99;//原年必为0 century--;//世纪也需-1 } } return ( (century%4*5 + year + year /4 + ( 13 * month - 27 ) / 5 + day)% 7 ); } 或 unsigned char CalcWeekDay (unsigned char century, unsigned char year, unsigned char month ,unsigned char day ) { if ( month <= 2) { month +=12 ;//今年的 1月 2月是去年的“13月14月” year--;//注意“去年”2字 if (year >= 99) {//年为无符号变量 year = 99;//原年必为0 century--;//世纪也需-1 } } return ( (century%4*5 + year + year /4 + ( 13 * month + 8 ) / 5 + day)% 7 ); } 或 unsigned char CalcWeekDay (unsigned char century, unsigned char year, unsigned char month ,unsigned char day ) { if ( month <= 2) { month |=4 ;//今年的 1月 2月是也是去年的“5月6月”的月表 year--;//注意“去年”2字 if (year >= 99) {//年为无符号变量 year = 99;//原年必为0 century--;//世纪也需-1 } } return ( (century%4*5 + year + year /4 + ( 13 * month + 8 ) / 5 + day)% 7 ); }
|
|
用户99599 2007-6-4 20:43
啊不好意思,错的是mistakes自己!
MOD(Y,400)×5 - INT(Y/4000)
1 - 0.9688 = 0.0312 × 97 = 3.02...
用户99599 2007-6-3 00:15
不会吧,应该懂英语的,难道还要等几千或几万年Gregorian再世才来解决这个问题。如感兴趣,我的邮箱是yhchen837@fastmail.fm,欢迎交流。
用户99599 2007-5-31 14:00
What years are leap years?
It takes the earth about 365.2422 days to go around the sun, but a normal calendar year is only 365 days. The extra fraction of a day adds up: circling the sun four times takes 1460.9688 days, but four calendar years would only be 1460 days. That .9688 is almost a whole day, so every four years we add an extra day to our calendar, February 29. We call that year leap year. To make things easier, leap years are always divisible by four: 2004 and 2008 will both be leap years.
For hundreds of years, people used a calendar called the Julian calendar that followed this rule, adding a leap year every four years. However, because .9688 isn't exactly a whole day, the Julian calendar slowly began to disagree with the real seasons. In 1582, Pope Gregory fixed this problem by ordering everyone to use a new set of rules. These rules are named the Gregorian calendar, after him. They work like this:
The Gregorian Calendar
Rule
Examples
Every fourth year is a leap year.
2004, 2008, and 2012 are leap years.
However, every hundredth year is not a leap year.
1900 and 2100 are not leap years.
Every four hundred years, there's a leap year after all.
2000 and 2400 are leap years.
People in English-speaking countries didn't start using the Gregorian calendar until 1752. Some countries, such as Iran, still use other systems.
答案(线索)就在里面,我想你一定能找出来!
雁塔菜农 2007-5-29 21:21
哈哈~~~这里的"百年"指年大于99的任何数,万年肯定在此~~~
参见:http://www.ednchina.com/blog/hotpower/30078/message.aspx
用户99599 2007-5-29 14:22
一万年后的今天是星期几?
个人觉得这是一个简单的小问题,你呢?
用户99599 2007-5-29 14:12
如果真是这样,还不如运用下面这个小学生都懂的通用公式,更为直接了当。
Y+Y/4+Y/400-Y/100,当然这只是千年公式不是万年公式!
雁塔菜农 2007-5-29 13:09
非常感谢您的参与!!!不过心算和计算机笨算很不同~~~
http://www.ednchina.com/blog/hotpower/30078/message.aspx
用户99599 2007-5-28 19:15
江小鸥:此法过于麻烦,我可用一法口算很快得出
是的,那就让我们来化简一下吧,但道理只有一个,你的也不例外。
千年某日星期速算法
公式:W = ( Y + M + D ) %7
Y = 百年%4*5天+年+年/4,M = 月星期表,D = 日。
月星期表1到12月
闰年 2 1 2 5 0 3 5 1 3 6 4 4
平年 6 2 2 5 0 3 5 1 3 6 4 4
心算时Y、 D可以分别先%7。
由于公元1月1日设为星期六,故3月1日为星期三。 ——注意这个“三”
为使算法达到最简,故本算法以“星期”为计算单位。且选3月1日为基月。
这个公元1月1日指哪一年?有必要选3月为基月吗?
9999年3月1日星期几=(99%4*5+99/4*5+99%4+3)%7=(120+15+3+3)%7=141%7=星期一。万年历实际上是骗人的,应该叫“四百年历”才是。万只是多的意思罢了。
是的,这个万年历星期速算法也是骗人的,因为9999年3月1日是星期六不是星期一。所谓的万年历是指它的算法适用万年,而不是指其对象的周期,所以把它改为千年。周期有大小之分,星期的最小周期是28年,这对心算尤为有用。
以上纯属个人观点,不一定对,JUST FOR YOUR REFERENCE!