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

析:因为算闰年的方法不同,所以我们就要先从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. BCB遍历所有窗体的组件

    for(iFormIdx=0; iFormIdx<Screen->FormCount; iFormIdx++) { TForm *pForm = Screen->Forms[iFor ...

  2. 函数buf_page_init

    /********************************************************************//** Inits a page to the buffer ...

  3. Ajax的“dataType”乱用的陷阱

    $.doAjax({ url : "areaAction_synchronizeArea.do", data : { 'vrvRangeUrl' : synAreaHTTP ,'v ...

  4. Selenium Tutorial (1) - Starting with Selenium WebDriver

    Starting with Selenium WebDriver Selenium WebDriver - Introduction & Features How Selenium WebDr ...

  5. android-async-http

    安装 http://blog.csdn.net/wangwei_cq/article/details/9453345 包内的一些基本的参数 http://www.cnblogs.com/manuose ...

  6. 使用Java VisualVM监控远程JVM

    我们经常需要对我们的开发的软件做各种测试, 软件对系统资源的使用情况更是不可少, 目前有多个监控工具, 相比JProfiler对系统资源尤其是内存的消耗是非常庞大,JDK1.6开始自带的VisualV ...

  7. [转](多实例)mysql-mmm集群

    一.需求说明 最近一直在学习mysql-mmm,想以后这个架构也能用在我们公司的业务上,我们公司的业务是单机多实例部署,所以也想把mysql-mmm部署成这样,功夫不负有心人,我成功了,和大家分享一下 ...

  8. LwIP编译方法以及选项说明

    条件编译命令 作用说明 IP_SOF_BROADCAST   LWIP_IGMP  

  9. iOS AFNetworking的使用

    转:http://www.cnblogs.com/lookenwu/p/3927897.html AFNetworking几乎是iOS上最常用的HTTP库了,AFNetworking也确实用起来简单, ...

  10. Hibernate优化

    前言 在一般情况下,Hibernate需要将执行转换为SQL语句从而性能低于JDBC.但是在经过比较好的性能优化之后,性能还是让人相当满意的,特别是应用二级缓存之后,甚至可以获得比较不使用缓存的JDB ...