An problem about date 根据年月日计算 星期几

/W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1、2月需要看作上一年的13、14月)

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
#include<limits.h>
using namespace std;
int main()
{
    int y, m, d, w;
    while(scanf("%d%d%d",&y,&m,&d)!=EOF)
    {
        if(m < 3)
        {
            m += 12;
            --y;
        }
        w =(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7;
        printf("%d\n",w);
    }
    return 0;
}
时间: 2024-08-02 12:25:49

An problem about date 根据年月日计算 星期几的相关文章

08--MOOC--C/C++ 根据年月日计算星期几——蔡勒公式篇

C/C++ 根据年月日计算星期几——蔡勒公式篇 蔡勒公式  蔡勒(Zeller)公式:是一个计算星期的公式.随便给一个日期,就能用这个公式推算出是星期几.蔡勒公式如下:W = [C/4] - 2C + y + [y/4] + [13 * (M+1) / 5] + d - 1或者是:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1公式中的符号含义如下:w:星期: w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六c:世纪-1(前两

蔡勒公式——根据年月日计算星期几

蔡勒(Zeller)公式,是一个计算星期的公式,随便给一个日期,就能用这个公式推算出是星期几. 计算公式 由于罗马教皇搞了一些骚操作,这里给出的公式仅适用于1582年10月15日以后的星期,详情可参考 格里高利历 符号意义 w:星期: w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六 c:世纪(注:一般情况下,在公式中取值为已经过的世纪数,也就是年份除以一百的结果,而非正在进行的世纪,也就是现在常用的年份除以一百加一:不过如果年份是公元前的年份且非

C# 根据日期计算星期几

1 region 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);) 2 /// <summary> 3 /// 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);) 4 /// </summary> 5 /// <param name="y">年</param> 6 /// <param name="m">

输入年月日计算是星期几

偶然的机会看到了一个计算星期几的算法,感觉很怪异并且很有意思就记录一下,也与大家共勉.自己写的代码有些瑕疵,但重点是计算星期的算法值得思索. 问题:输入年月日计算是星期几? 代码如下: #include <stdio.h>int getWeek(int year, int month, int day){ int aWeek[12] = {0,3,2,5,0,3,5,1,4,6,2,4}; int week = 0; int temp = 0; if(year < 1 || month

NYOJ-219 An problem about date

An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他. 输入 每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间; 输出 输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示) 样例输入 2011 3 6 1949 10 1 2011 4 1 1945 8 15 样例输出

An problem about date

An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他. 输入 每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间; 输出 输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示) 样例输入 2011 3 6 1949 10 1 2011 4 1 1945 8 15 样例输出

NYOJ219 An problem about date 【数学】

An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他. 输入 每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间; 输出 输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示) 样例输入 2011 3 6 1949 10 1 2011 4 1 1945 8 15 样例输出

IOS 获取年月日、星期

#pragma mark - 获取年月日及星期 + (NSString *)stringFromDate { // 添加日期 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendar

随机输入日期计算星期几(1900年1月1日为基础)

已知,1900年1月1日是星期1,用户随机输入年月日,计算星期几 代码如下(未改进),欢迎批评指正 year=int(input('year')) month=int(input('month')) day=int(input('day')) if year >=1900:#大于等于1900 ryear =1900 sum =0 while ryear < year:#1901 if ((ryear % 4 == 0) and (ryear %100 !=0))or(ryear % 400 =