2015年4月29日 dayofweek

时间:2022-09-23 21:07:09

#include <stdio.h>
#include <stdlib.h>
int DayofYear(int year, int month, int day);
#define ISYEAR(year) (year%400==0) ||(year%4==0&&year%100!=0)

int main(int argc, char *argv[])
{
/*已知1900年1月1日是星期一,输入一个年月日计算出来是星期几*/
int year, month, day;
char *week[]={"monday","tuesday","wedesday","thusday","friday","satday","sunday"};
int index, date1, date = 0;
scanf("%d%d%d",&year, &month, &day);
date1 = DayofYear(year, month, day);
if(year<1900){
printf("error\n");
return 0;
}
else
{
for(index=1900;index<year;index++){
if(ISYEAR(index))
{
date +=366;
}
else
date +=365;
}
}
printf("%s\n",week[(date+date1)%7]);

system("pause");
return 0;

}

int DayofYear(int year, int month, int day)
{
int sum = 0;
int index = 0;
for(index=1;index<month;index++){
switch(index){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sum += 31;
break;
case 2:
if(ISYEAR(year)){
sum += 29;
}
else 
sum +=28;
break;
case 4:
case 6:
case 9:
case 11:
sum += 30;
break;

}
}
sum += day;
return sum;
}

用已知日期的星期求输入日期的星期,小技巧,将已知日期(1900年1月1日)星期一保存在week数组的第0号元素,直接用相差的天数取模就可以得到结果。

2015年4月29日 dayofweek的更多相关文章

  1. 2015年9月29日html基础加强学习笔记

    创建一个最简便的浏览器 首先打开VS2010,然后在空间里拖出一个Form控件当主页面,其次拖出一个Textbox控件作为地址栏,然后加一个Button控件作为按钮,最后拖出一个WebBrowser作 ...

  2. 2015年9月29日 sql 触发器

    触发器(trigger):当有关联操作的时候使用(级联操作),属于ddl关键字. eg:下订单时,创建中的商品数量要减少:退票时,总的票数要增加.         在订单上建立触发器         ...

  3. 零基础学习云计算及大数据DBA集群架构师【企业级运维技术及实践项目2015年1月29日周五】

    LNMP/LEMP项目搭建 { 项目框架 # Linux_____WEB_____PHP_____DB # rhel7_____apache__-(libphp5.so)-__php__-(php-m ...

  4. 我的Python成长之路---第一天---Python基础(作业1:登录验证)---2015年12月26日(雾霾)

    作业一:编写登录接口 输入用户名密码 认证成功系那是欢迎信息 输错三次后锁定 思路: 1.参考模型,这个作业我参考了linux的登录认证流程以及结合网上银行支付宝等锁定规则 1)认证流程参考的是Lin ...

  5. Git学习(二)(2015年11月18日)(2016年1月29日)

    2015年11月18日Git学习: .Shell 删除文件夹及其所有文件 rd/s/q 文件目录 ---------------当前为先创建本地Git库后与网上Git服务器关联------------ ...

  6. 北京Uber优步司机奖励政策(11月23日~11月29日)

    用户组:人民优步"关羽组"(适用于11月23日-11月29日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最 ...

  7. 数据可视化之DAX篇(一)Power BI时间智能函数如何处理2月29日的?

    https://zhuanlan.zhihu.com/p/109964336 ​今年是闰年,有星友问我,在Power BI中,2月29日的上年同期是怎么计算的? 这是个好问题,正好梳理一下,Power ...

  8. 【hihoCoder】1148:2月29日

    问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...

  9. 2016年12月29日 星期四 --出埃及记 Exodus 21&colon;24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

随机推荐

  1. Centos7下安装python,查看python版本

    安装Centos的时候,一般会自带默认安装python2.x 一般用python -V可以查看python版本. 我当时安装的时候,运行了那个语句,但是却显示了一大堆出来,虽然里面也带有版本信息,但是 ...

  2. 省前训练&period;&period;&period;Orz

    A. 异形卵 Time Limit: 1000ms Memory Limit: 128000KB 64-bit integer IO format:      Java class name: Sub ...

  3. Spark2&period;0&period;0内存管理

    来源:http://spark.apache.org/docs/2.0.0/configuration.html spark中的内存使用主要分为两类:执行和存储.执行内存指的是用于shuffles.j ...

  4. JSOI2019 Round2 极限生还

    江苏省省队一共13个名额,去掉女生名额, 按1/3校内限制,我们南外只有4个名额, 在noip爆炸(占比35%),省选一轮爆炸(占比40%),(此时蒟蒻在校内排不进前10...) 总算在省选二轮(占比 ...

  5. February 22nd&comma; 2018 Week 8th Thursday

    Confine yourself to the present. 着眼当下. The morning wind spreads its fresh smell, we should get up an ...

  6. Spring Boot 与 OAuth2 官方最详细教程

    https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247484357&idx=1&sn=73e501de8591e6 ...

  7. jmeter 执行python脚本

    jmeter 可以通过Jython 执:行python代码 1.下载Jython jar包:http://www.jython.org/downloads.html 2.把下载的Jython 的jar ...

  8. Cortex-M3 and Cortex-M4 Memory Organization

    http://www.mikroe.com/download/eng/documents/compilers/mikropascal/pro/arm/help/memory_organization. ...

  9. simulink使用system test测试 (matlab2014a)

    simulink中有个工具system test,tools->systemtest->launch system test 打开.打开之后界面是这样的 选择insert->test ...

  10. PTA数据结构之 List Leaves

    Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...