题意:给定两个日期,两种不同算闰年的方法,导致日期不同,给定那个慢的,求你求了那个快的。

析:因为算闰年的方法不同,所以我们就要先从1582算到当前时间,算出差了多少天,再加上就好。注意跨月,跨年的情况。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
bool is_g(int y){
if(y % 400 == 0) return true;
if(y % 100 == 0) return false;
if(y % 4 == 0) return true;
return false;
} bool is_j(int y){
return y % 4 == 0;
}
bool f(int a, int b, int c)
{
int k = 28;
if(is_g(a)) k = 29;
if(b == 2 && c <= k) return true;
else if((b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) && (c <= 31)) return true;
else if((b == 4 || b == 6 || b == 9 || b == 11) && (c <= 30)) return true;
return false;
}
int cntj[10005];
int cntg[10005]; void solve(int y, int m, int d){
int cnt = cntj[y-1] - cntg[y-1];
if(m > 2 || (m == 2 && d > 28)) cnt += is_j(y) - is_g(y); cnt += 11;
while(cnt--)
{
d++;
if(f(y, m, d)) continue;
d = 1; m++;
if(f(y, m, d)) continue;
y++; m = 1; }
printf("%d-%02d-%02d\n", y, m, d);
} int main(){
int y, m, d;
for(int i = 1584; i <= 10000; i += 4){
++cntj[i];
cntg[i] += is_g(i);
}
for(int i = 1584; i <= 10000; ++i)
cntj[i] += cntj[i-1], cntg[i] += cntg[i-1]; while(~scanf("%d-%d-%d", &y, &m, &d)){
solve(y, m, d);
}
}

  

UVaLive 6627 First Date (转换时间)的更多相关文章

  1. 微信小程序中new Date()转换时间时间格式时IOS不兼容的问题

    本周写小程序,遇到的一个bug,在chrome上显示得好好的时间,一到Safari/iPhone 就报错 “invalid date”,时间格式为“2019.06.06 13:12:49”,然后利用n ...

  2. new Date在IE下面兼容问题

    昨天碰到一个bug,用art-template模板进行渲染时候,周视图任务展示失败,都是暂无任务,我以为是模板兼容问题,但最开始我用的时候记得就是IE8的兼容性问题,引入es5-shim.min.js ...

  3. 18 行 JS 代码编一个倒时器

    有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...

  4. JS 代码编一个倒时器

    有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...

  5. ASP.NET播客(留言时间,投票IP,留言限字数,上传视频)

    留言发布时间功能: 界面: 前台代码: 在Datalist控件中: 在<%#getIsDate(Convert.ToString(Eval("issuanceDate"))) ...

  6. iOS开发——时间格式类

    目前只实现了三个类方法, 第一个获取当前时间,以字符创的形式返回,例如"201606161532" 第二个以当前时间与给定时间的时间差(秒) 第三个以当前时间与给定时间的时间差(分 ...

  7. Swift基础之PickerView(时间)选择器

    代码讲解:(后面有额外代码讲解) 首页设计UIPickerView的样式设计: leftArray = ["花朵","颜色","形状"]; ...

  8. 日期类时间类,日期时间类,单例模式,装箱与拆箱,数字类随机数,BigDecimal总结

    1.日期类,时间类,日期时间类 初步日期使用方法及格式转换方法(旧方法): 格式://Mon Jul 30 11:26:05 CST 2018             年月日时分秒    CST代表北 ...

  9. Incorrect datetime value: '' for column 'examDate' at row 1

    出问题的程序:user.setCreateTime(new Date()); 控制台图片一张,问题是:Incorrect datetime value: '' for column 'createTi ...

随机推荐

  1. poj3307

    可以证明,每个符合的数都由2,3,5,7相乘得到. 依据猜想:下一个出现的数是由前面某个数乘上这几个数之一得到的新的数. 假设之前的数均满足序列,则因为下一个数必有2,3,5,7相乘得到,而这个数之前 ...

  2. bzoj3551 3545

    我直接来讲在线好了 这是一个很巧妙的方法,把边作为一个点 做一遍最小生成树,当加如一条边时,我们把这条边两点x,y的并查集的根i,j的父亲都设为这条边代表的点k,由k向i,j连边 这样我们就构建出一棵 ...

  3. 【C#学习笔记】载入图片并居中

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. 《C++ Primer 4th》读书笔记 第12章-类

    原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936473.html

  5. db2数据库Date相关函数

    1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2' FROM SYSIBM ...

  6. delphi 如何关闭 Unsafe typecast of 和 Unsafe type 的waring

    有时在Delphi使用指针类型的数据,总是提示如下: [Warning] FGroupFeedBack.pas(796): Unsafe typecast of 'Pointer' to 'TObje ...

  7. MySQL基础之第7章 索引

    第7章 索引 MySQL中,所有的数据类型都可以被索引,包括普通索引,唯一性索引,全文索引,单列索引,多列索引和空间索引等. 7.1.索引简介 7.1.1.索引的含义和特点 BTREE索引,HASH索 ...

  8. 在PHP中如何获取用户的真实IP

    /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $realip = NULL; ...

  9. Storm入门教程 第三章Storm集群安装部署步骤、storm开发环境

    一. Storm集群组件 Storm集群中包含两类节点:主控节点(Master Node)和工作节点(Work Node).其分别对应的角色如下: 主控节点(Master Node)上运行一个被称为N ...

  10. JAVA和C/C++之间的相互调用。

    在一些Android应用的开发中,需要通过JNI和 Android NDK工具实现JAVA和C/C++之间的相互调用. Java Native Interface (JNI)标准是java平台的一部分 ...