标签:
题意:给定两个日期,两种不同算闰年的方法,导致日期不同,给定那个慢的,求你求了那个快的。
析:因为算闰年的方法不同,所以我们就要先从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); } }
LA UVaLiva 6627 First Date (转换时间)
标签:
原文地址:http://www.cnblogs.com/dwtfukgv/p/5791596.html