编程介的小学生 2019-04-03 15:41 采纳率: 0.4%
浏览 1038

根据日期来推算今天是星期几的一个算法的问题怎么做,用C语言实现

Problem Description
Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?

Input
There are multiply cases.
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).

Output
Output one line.
if the date is illegal, you should output "illegal". Or, you should output what day it is.

Sample Input
2007 11 17

Sample Output
Saturday

  • 写回答

2条回答 默认 最新

  • 「已注销」 2019-04-03 16:06
    关注

    随便百度一个 计算星期的算法

    W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7
    
      在公式中d表示日期中的日数,m表示月份数,y表示年数。
    
    注意:在公式中有个与其他公式不同的地方:
    
     把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公式计算。
    

    然后判断一下合法就行了。

    评论

报告相同问题?