Calendar
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 12842   Accepted: 4641

Description

A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system. 
According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years. 
Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.

Input

The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer −1, which should not be processed. 
You may assume that the resulting date won’t be after the year 9999.

Output

For each test case, output one line containing the date and the day of the week in the format of "YYYY-MM-DD DayOfWeek", where "DayOfWeek" must be one of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".

Sample Input

1730
1740
1750
1751
-1

Sample Output

2004-09-26 Sunday
2004-10-06 Wednesday
2004-10-16 Saturday
2004-10-17 Sunday 注意:选取 Day of Week is Sunday 的日期作为基准日期.
#include <iostream>
using namespace std;
int mds[]={,,,,,,,,,,,,};
char Week[][]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
bool isLeap(int year)
{
if((year%==&&year%!=)||year%==)
{
return true;
}
return false;
}
int main()
{
int standard=;
for(int i=;i<=;i++)
{
if(isLeap(i)) standard+=;
else standard+=;
}
for(int i=;i<=;i++)
{
standard+=mds[i];
}
if(isLeap()) standard++;
standard+=;//2016-07-03 is Sunday.
int diff;
int days;
while(cin>>days&&days!=-)
{
diff=days-standard;
diff++;
int year=;
int d=;
int m=;
while(true)
{
if(isLeap(year))
{
if(days>=)
{
days-=;
year++;
}
else break;
}
else
{
if(days>=)
{
days-=;
year++;
}
else break;
}
}
while(true)
{
int ms=mds[m];
if(isLeap(year)&&m==)
{
ms++;
}
if(days>=ms)
{
days-=ms;
m++;
}
else break;
}
d+=days;
cout<<year<<"-";
if(m<) cout<<"";
cout<<m<<"-";
if(d<) cout<<"";
cout<<d<<" "; if(diff>=)
{
diff%=;
cout<<Week[diff]<<endl;
}
else
{
diff=-diff;
diff%=;
if(diff==) diff=;
cout<<Week[-diff]<<endl;
}
}
return ;
}

POJ2080:Calendar(计算日期)的更多相关文章

  1. Calendar计算日期

    一.周六三月进去.星期天 Calendar calendar=Calendar.getInstance();//当前日期 Calendar calendar2=Calendar.getInstance ...

  2. 计算日期时间 自动加1天 PHP计算闰年 java与PHP时间戳对比区别

    昨天写一个同步数据库的模块  从一个数据库同步到另外一个数据库,因为数据较多,不可能一次性全部搬迁过去,所以就按照每天搬迁! 写了一个 模块,点击加1,只要点击一次,自动从A数据库取出1天的数据, 并 ...

  3. js计算日期相差的天数

    在网站开发中,经常会遇到计算日期相差的天数,js 没有提供相应的方法,所以自己写一个,方便将来查看: 代码: function DateDiff(sDate1, sDate2, splitStr) { ...

  4. Java8中计算日期时间差

    一.简述 在Java8中,我们可以使用以下类来计算日期时间差异: 1.Period 2.Duration 3.ChronoUnit 二.Period类 主要是Period类方法getYears(),g ...

  5. sqlserver计算日期

    在网上找到的一篇文章,相当不错哦O(∩_∩)O~ 这是计算一个月第一天的SQL 脚本:  SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) --当月的第一 ...

  6. MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type)

    MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type) DATE_SUB(d,INTERVAL expr type)函数返回起始日期d减去一个时间段后的日期. expr是 ...

  7. PostgreSQL 当月最后一天的工作日 , 计算日期是星期几

    可以用pg自带函数select extract(dow from current_date),之所以没用主要是展示一下通过数学方法计算日期的原理. drop function if exists ge ...

  8. Java程序设计——反转字符串 & 找朋友 & 计算int型二进制1的个数 & 情报加密 & 计算日期 & 求近似数 & 输出较小数(练习1)

    作为刚刚入门Java的选手,其实C++的功底起到了很大的作用.但是,Java之于C++最大的不同,我个人认为,是其类的多样性.才入门的我,写着老师布置的简单的面对过程的题,如果是C++,可以算是简单了 ...

  9. Calendar计算一个月前的日期,踩坑记录

    错误示范:calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);//获取一个月前的今天这种写法假设传入的日期为2019-03-3 ...

随机推荐

  1. springboot工程的结构

    1 springboot的工程结构是什么 就是我们组织springboot工程时遵循的代码的目录结构. 2 spring initializr创建的工程的目录结构 源码目录:src/main/java ...

  2. 每天一个Linux命令(12)more命令

    more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作. 该命令一次显示一屏文本,满屏后停下来,并且在屏幕的底部出现一个提示信息,给出至今己显示 ...

  3. ICP 求解相机思路

    1.之前仍然是需要创建find_feature_matches,和pixel2cam,一个是用来匹配描述子的,一个是把像素坐标转成归一化平面坐标的.里面的变量都要带上&.2.因为是3d-3d. ...

  4. mysql的binlog太多太大占用了空间的解决办法

    现象:网站访问越来越慢,最后无法访问了,经过检查发现磁盘满了 分析过程及解决方案:通常出现这种问题都应该登录服务器检查磁盘.内存和进程使用的情况,通过top.df –h和free –m来检查,发现磁盘 ...

  5. sql的执行过程

    from ===> where ===> group by ===> select ===>order by 这个执行流程 很重要~~

  6. 4 Python 日期和时间

    Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为单位的浮点小数. ...

  7. mq_学习_00_资源帖

    一.精选 二.参考资料-基础 JMS(Java消息服务)入门教程 Sun Java System Message Queue 3.7 UR1 技术概述 消息队列-推/拉模式学习 & Activ ...

  8. Java企业微信开发_01_接收消息服务器配置

    一.准备阶段 需要准备事项: 1.一个能在公网上访问的项目: 见:Java微信公众平台开发_01_本地服务器映射外网 2.一个企业微信账号: 去注册:(https://work.weixin.qq.c ...

  9. deepmoji:文本预测emoji

    输入句子,预测emoji demo: https://deepmoji.mit.edu/ github: https://github.com/bfelbo/DeepMoji  能够被预测的emoji ...

  10. notepad++如何移除重复的行

    Removing duplicate rows in Notepad++ (so链接) 1. 插件 TextFX 2. 正则表达式:^(.*?)$\s+?^(?=.*^\1$)