zoukankan      html  css  js  c++  java
  • 题目标题: 高斯日记

    题目标题: 高斯日记
    大数学家高斯有个好习惯:无论如何都要记日记。
    他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210
    后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?
    高斯出生于:1777年4月30日。
    在高斯发现的一个重要定理的日记上标注着:5343,因此可算出那天是:1791年12月15日。
    高斯获得博士学位的那天日记上标着:8113 
    请你算出高斯获得博士学位的年月日。

    提交答案的格式是:yyyy-mm-dd, 例如:1980-03-21
    请严格按照格式,通过浏览器提交答案。
    注意:只提交这个日期,不要写其它附加内容,比如:说明性的文字。

    算术方法

    用整除和取余列个算式,就出来了。但要注意,闰年问题高斯出生的那天也算一天

    # include <stdio.h>
    int isLeap(int y);
    int nday(int y, int m, int d);
    void ymd(int n);
    int main(void)
    {
        int n = 8113;
        int yb = 1777, mb = 4, db = 30;    //birth
        n = n - 1 + nday(yb, mb, db);
        int yp, np;    //print
        for(int i = yb; n > 0; i++) {
            yp = i;
            np = n;
            if(isLeap(i)) {
                n -= 366;
            } else {
                n -= 365;
            }
        }
        printf("%d-", yp);
        ymd(np);
        return 0;
    }
    int nday(int y, int m, int d)
    {
        int n = 0;
        int a[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 
                        {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
        for(int i = 0; i < (m - 1); i++) {
            n += a[isLeap(y)][i];
        }
        n += d;
        return n;
    }
    void ymd(int n)
    {
        int a[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 
                        {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
        int mp, dp;
        for(int i = 0; n > 0; i++) {
            dp = n;
            mp = i;
            n -= a[isLeap(i)][i];
        }
        printf("%d-%d
    ", mp + 1, dp);
    }
    int isLeap(int y)
    {
        if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
            return 1;
        } else {
            return 0;
        }
    }
  • 相关阅读:
    如何将一个HTML页面嵌套在另一个页面中
    error while loading shared libraries: cannot restore segment prot after reloc: Permission denied错误原因[转]
    Sharepoint2007中的甘特图
    在Sharepoint2007新建站点
    开发Sharepoint2007的Webpart备忘
    厦门.NET俱乐部活动和准备Micorsoft TechReadyVisual Studio Team System深度培训有感
    Sharepoint2007中的用户选择器
    User Group Ready To Rock as well
    Sharepoint2007(OSS2007)重新学过
    Sharepoint2007列表中的目录
  • 原文地址:https://www.cnblogs.com/Deng1185246160/p/3608511.html
Copyright © 2011-2022 走看看