当前位置: 首页 > news >正文

模板 - 日期类

原来历史上1582年10月4日的下一天是1582年10月15日;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Date {
    int y, m, d;

    Date(int y=0,int m=0,int d=0):y(y),m(m),d(d){}

    void nextDate() {
        ++d;
        carryDay();
    }
    void carryDay() {
        if(y==1582&&m==10&&d==5){
            d=15;
            return;
        }

        if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
            if(d == 32) {
                d = 1;
                ++m;
                carryMonth();
            }
        } else if(m != 2) {
            if(d == 31) {
                d = 1;
                ++m;
            }
        } else {
            if(isLeapYear()) {
                if(d == 30) {
                    d = 1;
                    ++m;
                }
            }
            else{
                if(d == 29) {
                    d = 1;
                    ++m;
                }
            }
        }
    }

    void carryMonth(){
        if(m==13){
            m=1;
            ++y;
        }
    }

    bool isLeapYear(){
        return (y%4==0&&y%100!=0||y%400==0);
    }

    ll toLongLong(){
        return (10000ll*y+100ll*m+d);
    }

    int Zeller(){
        //0 是 星期日
        if(y>1582||(y==1582&&(m>10||(m==10&&d>4))))
           return Zeller1();
        else
            return Zeller2();
    }

    int Zeller1(){
        int _c,_y=y,_m=m,_d=d;
        if(_m<=2)
            _m+=12,_y-=1;
        _c=_y/100;
        _y%=100;
        return ((_y+_y/4+_c/4-2*_c+13*(_m+1)/5+_d-1)%7+7)%7;
    }
    int Zeller2(){
        int _c,_y=y,_m=m,_d=d;
        if(_m<=2)
            _m+=12,_y-=1;
        _c=_y/100;
        _y%=100;
        return ((_y+_y/4+_c/4-2*_c+13*(_m+1)/5+_d+2)%7+7)%7;
    }
}date;

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    date=Date(1500,1,1);
    int cnt=0;
    for(int i=1;i<=50000;++i){
        cout<<date.toLongLong()<<" "<<date.Zeller()<<" ";
        ++cnt;
        if(cnt==7){
            cnt=0;
            puts("");
        }

        date.nextDate();
    }
    //cout<<date.Zeller();
}

转载于:https://www.cnblogs.com/Yinku/p/11297949.html

相关文章:

  • POJ数学题目
  • SCUT - 142 - 第n个素数
  • 敏捷开发般若敏捷系列之二:什么是敏捷(上)(无住,不住于法,破法执)...
  • C#打包应用程序
  • SCUT - 37 - 手速帝CZK - 分块
  • HDU 1166 敌兵布阵
  • babel
  • 转载 对于struct file_operations中ioctl消失的学习笔记
  • SCUT - 77 - 哈利波特与他的魔法杖
  • 圆满完成 中大 《性能测试与LoadRunner应用》 实战训练课!
  • 利用vi编辑器创建和编辑正文文件
  • c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
  • Simulation of AVL Trees (DYNAMIC)
  • hive中function函数查询
  • 更改Windwos server 2003 域用户密码策略默认配置
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • Angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  • Angularjs之国际化
  • Brief introduction of how to 'Call, Apply and Bind'
  • canvas实际项目操作,包含:线条,圆形,扇形,图片绘制,图片圆角遮罩,矩形,弧形文字...
  • Java到底能干嘛?
  • leetcode388. Longest Absolute File Path
  • Making An Indicator With Pure CSS
  • nginx 配置多 域名 + 多 https
  • python学习笔记 - ThreadLocal
  • python学习笔记-类对象的信息
  • React-flux杂记
  • Redis 懒删除(lazy free)简史
  • Spring Boot快速入门(一):Hello Spring Boot
  • springMvc学习笔记(2)
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • vue从入门到进阶:计算属性computed与侦听器watch(三)
  • 半理解系列--Promise的进化史
  • 规范化安全开发 KOA 手脚架
  • 类orAPI - 收藏集 - 掘金
  • 问题之ssh中Host key verification failed的解决
  • 学习笔记DL002:AI、机器学习、表示学习、深度学习,第一次大衰退
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 移动端唤起键盘时取消position:fixed定位
  • 源码之下无秘密 ── 做最好的 Netty 源码分析教程
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • # 安徽锐锋科技IDMS系统简介
  • (done) 两个矩阵 “相似” 是什么意思?
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (超详细)2-YOLOV5改进-添加SimAM注意力机制
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (九十四)函数和二维数组
  • (七)Knockout 创建自定义绑定
  • (四)模仿学习-完成后台管理页面查询
  • (转)linux下的时间函数使用
  • (转)人的集合论——移山之道
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • ******之网络***——物理***
  • .htaccess配置重写url引擎
  • .NET 6 在已知拓扑路径的情况下使用 Dijkstra,A*算法搜索最短路径