zoukankan      html  css  js  c++  java
  • First Date (hnoj12952)日期计算

    First Date
    Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB
    Total submit users: 77, Accepted users: 46
    Problem 12952 : No special judgement
    Problem description

    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
    1582-10-04
    1752-09-02
    1900-02-25
    1923-02-15
    Sample Output
    1582-10-15
    1752-09-14
    1900-03-10
    1923-03-01

    题意:J日历闰年只要被4整除;G日历能被4整除但不能被100整除,或者能被400整除的是闰年;

      先在已知J的日历日期,问你G的日历显示的日期?

    表示自己不会算钱,这次连日子都算不好。。。。。。。。。。。。。悲剧!

    这次就被黑在这里了。。。。。无语。

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12952

    AC代码:

    #include<stdio.h>
    
    void Print(int h,int m,int s)
    {
        printf("%d",h);
    
        if(m>9) printf("-%d",m);
        else     printf("-0%d",m);
        if(s>9) printf("-%d
    ",s);
        else     printf("-0%d
    ",s);
    }
    int main()
    {
        int i,j,d;
        int sum;
        int hh,mm,ss;
        int year,mouth,day;
        int s1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
        int s2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
    while(~scanf("%d-%d-%d",&hh,&mm,&ss))
        {
    
            int fa,fb,fc,fd;
    //           fa=hh/4;
            fb=hh/100;
            fc=hh/400;
            fd=fb-fc-1;
            year=hh;
            mouth=mm;
            day=ss+fd;
    //           printf("%d	%d	%d	%d
    ",fa,fb,fc,fd);
            sum=0;
    //           printf("%d
    ",day);
            if(year%100==0&&year%400!=0&&mm<=2)
                day--;
            for(i=mm; i<13; i++)
            {
                //          sum+=s1[i];
                if(i==2&&((year%4==0&&year%100!=0)||year%400==0))
                {
                    if(day>29)
                    {
                        day-=29;
                        mouth++;
                        if(mouth>12)
                        {
                            mouth=1;
                            i=0;
                            year++;
                        }
                    }
                    else
                        break;
                }
    
                else if(day>s1[i])
                {
                    day-=s1[i];
                    mouth++;
                    if(mouth>12)
                    {
                        mouth=1;
                        i=0;
                        year++;
                    }
                }
                else
                    break;
    
            }
            Print(year,mouth,day);
        }
        return 0;
    }

    超时,和RE的代码。。。。呜呜,过不了

    why?

    #include<stdio.h>
    #include<string.h>
    
    #define ll __int64
    
    int leapj(ll y)
    {
        if(y%4==0)
            return 1;
        else
            return 0;
    }
    int leapg(ll y)
    {
        if(((y%4==0)&&(y%100!=0))||(y%400==0))
            return 1;
        else
            return 0;
    }
    
    void Print(ll h,ll m,ll s)
    {
        printf("%I64d",h);
    
        if(m>9) printf("-%I64d",m);
        else     printf("-0%I64d",m);
        if(s>9) printf("-%I64d
    ",s);
        else     printf("-0%I64d
    ",s);
    }
    int main()
    {
        ll i,j,d;
        ll num;
        ll hh,mm,ss;
        ll HH,MM,SS;
        ll s1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
        ll s2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
        ll s3[13]= { 0,0, 0, 0, 0, 0, 0, 0, 0, 0,27,30,31};
        while(~scanf("%I64d-%I64d-%I64d",&hh,&mm,&ss))
        {
            ll a=(hh-1580)/4;
            if(leapj(hh)&&(mm==1||mm==2)&&ss<29)
                a--;
    
    
    //        printf("a    %d
    ",a);
    
            num=(hh-1582)*365+a+11;
            if(hh>1582)
            {
                for(j=1;j<mm; j++)
                {
                    num+=s1[j];
                }
     //           if(leapj(hh)&&(mm==2&&ss==29||mm>2))
     //               num++;
                num+=ss;
            }
    //        printf("num    %I64d
    ",num);
    //        printf("hh   %d
    ",hh);
            if(hh==1582&&num<=88)
            {
                for(j=10; j<13; j++)
                {
                    if(num>s3[j])
                    {
                        num-=s3[j];
                        mm++;
                    }
                    else
                        break;
                }
                ss+=num;
                Print(hh,mm,ss);
            }
    
            else
            {
            //    num-=365;
    //           printf("hh    %d
    ",hh);
                HH=1583;
    
                while(num>=366)
                {
    //              printf("%I64d	%d
    ",num,hh);
                    num-=365;
                    if(((HH%4==0)&&(HH%100!=0))||(HH%400==0))
                        num--;
                    HH++;
                }
    
                MM=0;
                SS=0;
     //         printf("%I64d    %I64d
    ",num,HH);
                if(leapg(HH))
                {
                    for(j=1; j<13; j++)
                    {
                        MM++;
                        if(num>s2[j])
                        {
                            num-=s2[j];
                        }
                        else
                            break;
                    }
                    SS=num;
                }
                else
                {
                    for(j=1; j<13; j++)
                    {
                        MM++;
                        if(num>s1[j])
                        {
                            num-=s1[j];
                        }
                        else
                            break;
                    }
                    SS=num;
                }
    
                Print(HH,MM,SS);
            }
    
        }
        return 0;
    }
  • 相关阅读:
    PHP 消息队列
    Nginx 设置负载均衡
    Nginx 服务器搭建
    PHP 获取文件扩展名的五种方式
    高并发和大流量解决方案
    <面试> PHP 常见算法
    Mysql 预查询处理 事务机制
    Linux定时任务 结合PHP实现实时监控
    Swoole 结合TP5搭建文字直播平台
    <记录> PHP Redis操作类
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/3948303.html
Copyright © 2011-2022 走看看