UESTC 893 First Date 计算时间

点击打开链接

First Date

Time Limit: 5678/1234MS (Java/Others)     Memory Limit: 65432/65432KB (Java/Others)

Submit 
Status

In 1582, pope Gregory XIII decreed a calendar reform to bring the mean length of the calendar year (counted in days) more in line with the actual number of days in an astronomical year. This calendar reform entailed
a transition from the Julian calendar to the Gregorian calendar.

Both the Julian and Gregorian calendars have regular years with 365 days, and so-called leap years with 366 days. In regular years, the month February has 28 days, while in leap years, it has
an extra leap day: February 29th.

The single difference between the Julian and Gregorian calendars is in their rule to determine if a year is a leap year. In the Julian calendar, leap years are those years that are divisible by~4. The Gregorian
calendar‘s rule for determining leap years is a bit more complicated: years divisible by 4 are leap years, unless they are divisible by 100 but not by 400.

Following these rules, the years 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, and 2400 are all leap years in the Julian calendar. In the Gregorian calendar, the only leap years in this list are 1600, 2000, and
2400.

The old Julian calendar has a mean year length of 365.25 days, while the new Gregorian calendar has a mean year length of 365.2425 days. Given that the actual number of days in an astronomical year is about 365.24219
days, you can see why the Gregorian calendar is an improvement.

As part of the Gregorian reform, a number of dates were skipped, to reverse the effects of having used the Julian calendar for over 1500 years. Specifically, the Gregorian reform decreed that October~4, 1582 (Julian)
was to be followed by October~15, 1582 (Gregorian).

However, by the end of the 16th century the Reformation was in full swing. While the Catholic countries tended to follow the Papal decree, many countries continued using the Julian calendar until much later. For
example, the United Kingdom switched from the Julian calendar to the Gregorian calendar on September~2, 1752 (Julian) which was followed by September~14, 1752 (Gregorian) --- by that time, 11 dates had to be skipped to make the switch. The last European country
to switch was Greece, which made the transition as late as February~15, 1923 (Julian) which was followed by March~1, 1923 (Gregorian), skipping 13 dates.

Given the last day for which the Julian calendar is in effect for some country (expressed as a Julian date), determine the next day‘s Gregorian date, i.e., the first date that uses the Gregorian calendar.

Input

For each test case, the input consists of one line containing a date in the Julian calendar, formatted as YYYY-MM-DD.
This date will be no earlier than October~4, 1582, and no later than October~18, 9999. The given date represents the last day that the Julian calendar is in effect for some country.

Output

For each test case, print the first Gregorian date after the calendar transition.

Sample input and output

Sample Input Sample Output
1582-10-04
1752-09-02
1900-02-25
1923-02-15
1582-10-15
1752-09-14
1900-03-10
1923-03-01

Source

Northwestern European Regional Contest 2013

求出给出的年份增加的天数n,在此年份上增加n就是所求。

//800 KB	191 MS
#include<stdio.h>
int judge(int x,int y)
{
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)return 31;
    if(x==4||x==6||x==9||x==11)return 30;
    if(x==2&&((y%4==0&&y%100!=0)||(y%400==0)))return 29;
    return 28;
}
int main()
{
    int y,m,d;
    while(scanf("%d-%d-%d",&y,&m,&d)!=EOF)
    {
        int ans=d;
        if(y%400!=0&&y%100==0&&m>2)ans++;
        for(int i=100; i<=y-1; i+=100)
            if(i%400!=0)ans++;
        ans--;
        while(ans>judge(m,y))
        {
            ans-=judge(m,y);
            m++;
            if(m==13){y++; m=1;}
        }
        printf("%d-%02d-%02d\n",y,m,ans);
    }
    return 0;
}

时间: 2024-10-19 15:05:28

UESTC 893 First Date 计算时间的相关文章

java为啥计算时间从1970年1月1日开始

http://www.myexception.cn/program/1494616.html ---------------------------------------------------------- java为什么计算时间从1970年1月1日开始 今天在看Python  API 时,看到 time 模块 : The epoch is the point where the time starts. On January 1st of that year, at 0 hours,the

计算时间

NSDate+MJ.h #import <Foundation/Foundation.h> @interface NSDate (MJ) /** * 是否为今天 */ - (BOOL)isToday; /** * 是否为昨天 */ - (BOOL)isYesterday; /** * 是否为今年 */ - (BOOL)isThisYear; /** * 返回一个只有年月日的时间 */ - (NSDate *)dateWithYMD; /** * 获得与当前时间的差距 */ - (NSDateC

js 计算时间

var date1=new Date();  //开始时间 var date2=new Date();    //结束时间 var date3=date2.getTime()-date1.getTime()  //时间差的毫秒数 ------------------------------ //计算出相差天数 var days=Math.floor(date3/(24*3600*1000)) //计算出小时数 var leave1=date3%(24*3600*1000)    //计算天数后剩

自学php找工作【二】 PHP计算时间加一天

最近几天在做一个项目,主要是将SQLserver数据到MySQL数据库,一个url跑一次 同步一次昨天的数据,由于很多数据需要同步,所以做了一个操作界面的,一个单纯跑url的 在其中涉及到了对于时间的计算!当我写完这个程序的时候,我回头看我写的计算时间的代码.有些都有点儿懵了!...在这里记录下来方便以后回忆,也方便别人使用! 代码可能会臃肿!新人一枚!欢迎指正!拒绝骂街哦! 先简单说一下代码,其中主要涉及到计算润年 平年,计算28天 31天 30天月份 等,主要就是判断!代码中有注释,大家看一

根据上下午计算时间

$(function () { if ($() { $("input[name='DATA_16']").attr("onchange", "jsTime()"); $("input[name='DATA_17']").attr("onchange", "jsTime()"); $("select[name='DATA_18']").attr("onchan

php 中date显示时间不对与Linux文件乱码问题

php 中date显示时间不对解决办法如下1.修改/etc/php.ini文件 在里头中找到data.timezone =去掉它前面的分号';' 然后设置data.timezone = "Asia/Shanghai";即可 2.在程序代码中使用函数date_default_timezone_set('Asia/Shanghai'); 或者date_default_timezone_set('PRC'); 即可 LINUX 系统显示中文文件乱码 解决办法如下 1.永久解决 输入local

&quot;/Date(1405056837780)/&quot; 时间转换

//往往json传过来的时间都是"/Date(1405056837780)/" //转换需要的方法 String.prototype.ToString = function (format) { var dateTime = new Date(parseInt(this.substring(6, this.length - 2))); format = format.replace("yyyy", dateTime.getFullYear()); format =

php date()日期时间函数详解

PHP(PHP培训 php教程 )中date()日期时间函数详解,需要的朋友可以参考下. 1,年-月-日 echo date('Y-m-j'); 2007-02-6 echo date('y-n-j'); 07-2-6 大写Y表示年四位数字,而小写y表示年的两位数字; 小写m表示月份的数字(带前导),而小写n则表示不带前导的月份数字. echo date('Y-M-j'); 2007-Feb-6 echo date('Y-m-d'); 2007-02-06 大写M表示月份的3个缩写字符,而小写m

js new Date() 获取时间

js new Date() 获取时间 Date 对象用于处理日期和时间.创建 Date 对象的语法:var myDate=new Date()Date 对象会自动把当前日期和时间保存为其初始值.参数形式有以下5种: new Date("month dd,yyyy hh:mm:ss");new Date("month dd,yyyy");new Date(yyyy,mth,dd,hh,mm,ss);new Date(yyyy,mth,dd);new Date(ms);