POJ2080:Calendar(计算日期)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 12842 | Accepted: 4641 |
Description
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
You may assume that the resulting date won’t be after the year 9999.
Output
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(计算日期)的更多相关文章
- Calendar计算日期
一.周六三月进去.星期天 Calendar calendar=Calendar.getInstance();//当前日期 Calendar calendar2=Calendar.getInstance ...
- 计算日期时间 自动加1天 PHP计算闰年 java与PHP时间戳对比区别
昨天写一个同步数据库的模块 从一个数据库同步到另外一个数据库,因为数据较多,不可能一次性全部搬迁过去,所以就按照每天搬迁! 写了一个 模块,点击加1,只要点击一次,自动从A数据库取出1天的数据, 并 ...
- js计算日期相差的天数
在网站开发中,经常会遇到计算日期相差的天数,js 没有提供相应的方法,所以自己写一个,方便将来查看: 代码: function DateDiff(sDate1, sDate2, splitStr) { ...
- Java8中计算日期时间差
一.简述 在Java8中,我们可以使用以下类来计算日期时间差异: 1.Period 2.Duration 3.ChronoUnit 二.Period类 主要是Period类方法getYears(),g ...
- sqlserver计算日期
在网上找到的一篇文章,相当不错哦O(∩_∩)O~ 这是计算一个月第一天的SQL 脚本: SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) --当月的第一 ...
- MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type)
MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type) DATE_SUB(d,INTERVAL expr type)函数返回起始日期d减去一个时间段后的日期. expr是 ...
- PostgreSQL 当月最后一天的工作日 , 计算日期是星期几
可以用pg自带函数select extract(dow from current_date),之所以没用主要是展示一下通过数学方法计算日期的原理. drop function if exists ge ...
- Java程序设计——反转字符串 & 找朋友 & 计算int型二进制1的个数 & 情报加密 & 计算日期 & 求近似数 & 输出较小数(练习1)
作为刚刚入门Java的选手,其实C++的功底起到了很大的作用.但是,Java之于C++最大的不同,我个人认为,是其类的多样性.才入门的我,写着老师布置的简单的面对过程的题,如果是C++,可以算是简单了 ...
- Calendar计算一个月前的日期,踩坑记录
错误示范:calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);//获取一个月前的今天这种写法假设传入的日期为2019-03-3 ...
随机推荐
- [Oracle]根据字段值全库搜索相关数据表和字段
这个需求比较冷门,但对于在某些特定的情况下,还是会有这样的需要的.好在Oracle实现还比较方便,用存储过程则轻松实现. 查询字符串: create or replace procedure sear ...
- less (css预处理)
用法 1. 必须在head内 2. 样式文件必须先加载 <head> <meta charset='utf-8'> <link rel="stylesheet/ ...
- 我的Android进阶之旅------>介绍一款集录制与剪辑为一体的屏幕GIF 动画制作工具 GifCam
由于上一篇文章:我的Android进阶之旅------>Android之动画之Frame Animation实例 中展示的是Frame动画效果,但是之前我是将图片截取下来,不好说明确切的动画过程 ...
- Linux软连接和硬连接
软连接 命令: ln -s 原文件 目标文件 特征: 1.相当于windows的快捷方式 2.只是一个符号连接,所以软连接文件大小都很小 3.当运行软连接的时候,会根据连接指向找到真正的文件,然后执行 ...
- SAP内表转XML文件
今天有个兄弟问如何实现以XML的方式输出内表的内容,这个问题我以前好像没有写过.倒不是不会写,而是写的方法太多了,有极其简单的,也有很复杂的,而且网上资料也很多. 找到以前写的一个程序,稍微修改了一下 ...
- c语言操作mysql数据库
c语言操作Mysql数据库,主要就是为了实现对数据库的增.删.改.查等操作,操作之前,得先连接数据库啊,而连接数据库主要有两种方法.一.使用mysql本身提供的API,在mysql的安装目录中可可以看 ...
- PIG执行MR时报Connection refused错误
原因是jobhistory没有启动,其启动脚本位于hadoop/sbin目录下 启动命令如下 mr-jobhistory-daemon.sh start historyserver
- [转]eclipse中的常用快捷键
1.选中你要加注释的区域,用ctrl+shift+C 会加上//注释2.先把你要注释的东西选中,用shit+ctrl+/ 会加上注释3.要修改在eclispe中的命令的快捷键方式我们只需进入windo ...
- linux FAQ(zz)
1.Which is the command used to find the available shells in your Operating System Linux ? Ans : $ech ...
- perl常用字符串函数
1.$position = index(string,substring,skipchars): 该函数返回子串substring在字符串string中的位置,如果不存在,则返回-1:参数skipch ...