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. ConfigurableBeanFactory

    ConfigurableBeanFactory :关系如下 在上面这样的一个关系图中可以先看下SingletonBeanRegistry的源代码: package org.springframewor ...

  2. Future Promise 模式(netty源码9)

    netty源码死磕9  Future Promise 模式详解 1. Future/Promise 模式 1.1. ChannelFuture的由来 由于Netty中的Handler 处理都是异步IO ...

  3. bug_1——oracle listagg():列转行

    select    listagg(字段名 ,',') within group (order by 字段名) from表 where 条件 listagg():列转行 WM_CONCAT():和并列 ...

  4. oldboyshell编程扩展内容

    oldboyshell编程扩展内容一.命令的优先级 命令分为: ==> alias ==> Compound Commands ==> function  ==> build_ ...

  5. UIImageView 获取图片的 宽 高

    该文章纯属这两天开发的经验之谈 并且也是平常没注意 这回发现的一个小方法 并且很实用 在开发中 提高了很大的效率 更加符合高保真的要求 通常 美术 切的一些图片 需要 :1还原的 现在 我们一般支持i ...

  6. C#仿QQ设置界面导航

    效果预览,选择左边标签,右边内容会自动滚动到适当位置 public class AnchorPanel { List<PanelMenu> lst = new List<PanelM ...

  7. 【leetcode刷题笔记】Valid Number

    Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...

  8. web框架详解之tornado 一 模板语言以及框架本质

    一.概要 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过 ...

  9. python内置方法补充all

    all(iterable) 版本:该函数在python2.5版本首次出现,适用于2.5以上版本,包括python3,兼容python3版本. 说明:如果iterable的所有元素不为0.''.Fals ...

  10. redis主从架构及redis集群

    https://redis.io/topics/cluster-spec Redis Cluster does not support multiple databases like the stan ...