hnu 12952 First Date
来源:互联网 发布:centos git服务器 编辑:程序博客网 时间:2024/06/06 10:48
Given the last day for which the Julian calendar is in effect for some country (expressed as a Julian date), determine the next day’s Gregorian date, i.e., the first date that uses the Gregorian calendar.
Input
For each test case, the input consists of one line containing a date in the Julian calendar, formatted as YYYY-MM-DD. This date will be no earlier than October 4, 1582, and no later than October 18, 9999. The given date represents the last day that the Julian calendar is in effect for some country.
Output
For each test case, print the first Gregorian date after the calendar transition.
Sample Input
1582-10-041752-09-021900-02-251923-02-15Sample Output
1582-10-151752-09-141900-03-101923-03-01
讲述两种日历的记录方法 两种方法的差异在于闰年的判断方法
前一种方法只要整除4就是闰年 第二种方法 就是当整除100的时候判断是否正常400
然后现在要将前一种日历的记录方法转换为第二种 因为第一种方法中闰年计算多了 就多算了天数
转换为第二种之后现在的日期要往后推
就是计算出多算了几个闰年就可以了 这里要注意 如果现在的时间的年份是整除100的 且月份超过了2 这一天也是多算的
转换日子的过程中要判断是否跨月 是否跨年 模拟这个过程就可以了
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD 10009#define MAXN 100100#define FOR(i,a,b) for(int i=a;i<=b;i++)#define FOV(i,a,b) for(int i=a;i>=b;i--)#define REP(i,a,b) for(int i=a;i<b;i++)#define REV(i,a,b) for(int i=a-1;i>=b;i--)#define MEM(a,x) memset(a,x,sizeof a)#define ll __int64using namespace std;int mm[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 y,m,d;int isleap(int yy){ int flag=0; if(yy%100==0) { if(yy%400==0) flag=1; } else { if(yy%4==0) flag=1; } return flag;}void print(){ int sum=0; for(int i=100; i<y; i+=100) { if(i%400) sum++; } if(m>2&&(y%100)==0) { if(y%400) sum++; } sum-=1;// cout<<sum<<endl; //跨月 跨年 int flag=0;//是否是闰年 flag=isleap(y); int x=sum-(mm[flag][m-1]-d); if(x<=0) { d+=sum; if(d<10) { if(m<10) { printf("%d-0%d-0%d\n",y,m,d); return; } else { printf("%d-%d-0%d\n",y,m,d); return; } } else { if(m<10) { printf("%d-0%d-%d\n",y,m,d); return; } else { printf("%d-%d-%d\n",y,m,d); return; } } } sum-=(mm[flag][m-1]-d); d=0; while(x>0) { m++; if(m==13) { m=1; y++; flag=isleap(y); } x=sum-mm[flag][m-1]; if(x<=0) { d+=sum; if(d<10) { if(m<10) { printf("%d-0%d-0%d\n",y,m,d); return; } else { printf("%d-%d-0%d\n",y,m,d); return; } } else { if(m<10) { printf("%d-0%d-%d\n",y,m,d); return; } else { printf("%d-%d-%d\n",y,m,d); return; } }// x=0; } sum-=(mm[flag][m-1]-d); }}int main(){//freopen("ceshi.txt","r",stdin); while(scanf("%d-%d-%d\n",&y,&m,&d)!=EOF) { print(); } return 0;}
- hnu 12952 First Date
- First Date
- First Date
- Greedy --- HNU 13320 Please, go first
- UESTC 893&&uvalive 6627 First Date
- UESTC 893 First Date 计算时间
- UESTC 893 First Date 计算时间
- First Date (hnoj12952)日期计算
- HNU 11877
- hnu 病毒
- hnu 12948
- HNU Profits
- HNU 21
- acm hnu 10136 Palindromes
- hnu 12029 LCA问题
- hnu 12439 #贪心
- [讨论]hnu 12450 Painting
- hnu-City Merger
- Count and Say
- DHCP Snooping技术
- ThinkPad E430C从待机状态恢复后,无线网络就不可用了
- 方向对就死磕 微信不是唯一选择
- NBA球队信息管理系统
- hnu 12952 First Date
- R语言基础入门2--基本数据类型
- Ubuntu10.04中利用V4L2读取摄像头数据并保存成文件
- 《Hadoop实战》(陆嘉恒著) 读书笔记
- 移动数字化医疗
- 算法之分治法
- 手游渠道出现三大变量
- SQL入门(2)——数据库的备份和恢复
- Android开发大牛博客