First Date (hnoj12952)日期计算
来源:互联网 发布:ubuntu源arm 编辑:程序博客网 时间:2024/06/06 03:31
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
题意:J日历闰年只要被4整除;G日历能被4整除但不能被100整除,或者能被400整除的是闰年;
先在已知J的日历日期,问你G的日历显示的日期?
表示自己不会算钱,这次连日子都算不好。。。。。。。。。。。。。悲剧!
这次就被黑在这里了。。。。。无语。
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12952
AC代码:
#include<stdio.h>void Print(int h,int m,int s){ printf("%d",h); if(m>9) printf("-%d",m); else printf("-0%d",m); if(s>9) printf("-%d\n",s); else printf("-0%d\n",s);}int main(){ int i,j,d; int sum; int hh,mm,ss; int year,mouth,day; int s1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; int s2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};while(~scanf("%d-%d-%d",&hh,&mm,&ss)) { int fa,fb,fc,fd;// fa=hh/4; fb=hh/100; fc=hh/400; fd=fb-fc-1; year=hh; mouth=mm; day=ss+fd;// printf("%d\t%d\t%d\t%d\n",fa,fb,fc,fd); sum=0;// printf("%d\n",day); if(year%100==0&&year%400!=0&&mm<=2) day--; for(i=mm; i<13; i++) { // sum+=s1[i]; if(i==2&&((year%4==0&&year%100!=0)||year%400==0)) { if(day>29) { day-=29; mouth++; if(mouth>12) { mouth=1; i=0; year++; } } else break; } else if(day>s1[i]) { day-=s1[i]; mouth++; if(mouth>12) { mouth=1; i=0; year++; } } else break; } Print(year,mouth,day); } return 0;}
超时,和RE的代码。。。。呜呜,过不了
why?
#include<stdio.h>#include<string.h>#define ll __int64int leapj(ll y){ if(y%4==0) return 1; else return 0;}int leapg(ll y){ if(((y%4==0)&&(y%100!=0))||(y%400==0)) return 1; else return 0;}void Print(ll h,ll m,ll s){ printf("%I64d",h); if(m>9) printf("-%I64d",m); else printf("-0%I64d",m); if(s>9) printf("-%I64d\n",s); else printf("-0%I64d\n",s);}int main(){ ll i,j,d; ll num; ll hh,mm,ss; ll HH,MM,SS; ll s1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; ll s2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31}; ll s3[13]= { 0,0, 0, 0, 0, 0, 0, 0, 0, 0,27,30,31}; while(~scanf("%I64d-%I64d-%I64d",&hh,&mm,&ss)) { ll a=(hh-1580)/4; if(leapj(hh)&&(mm==1||mm==2)&&ss<29) a--;// printf("a %d\n",a); num=(hh-1582)*365+a+11; if(hh>1582) { for(j=1;j<mm; j++) { num+=s1[j]; } // if(leapj(hh)&&(mm==2&&ss==29||mm>2)) // num++; num+=ss; }// printf("num %I64d\n",num);// printf("hh %d\n",hh); if(hh==1582&&num<=88) { for(j=10; j<13; j++) { if(num>s3[j]) { num-=s3[j]; mm++; } else break; } ss+=num; Print(hh,mm,ss); } else { // num-=365;// printf("hh %d\n",hh); HH=1583; while(num>=366) {// printf("%I64d\t%d\n",num,hh); num-=365; if(((HH%4==0)&&(HH%100!=0))||(HH%400==0)) num--; HH++; } MM=0; SS=0; // printf("%I64d %I64d\n",num,HH); if(leapg(HH)) { for(j=1; j<13; j++) { MM++; if(num>s2[j]) { num-=s2[j]; } else break; } SS=num; } else { for(j=1; j<13; j++) { MM++; if(num>s1[j]) { num-=s1[j]; } else break; } SS=num; } Print(HH,MM,SS); } } return 0;}
- First Date (hnoj12952)日期计算
- Date 计算日期
- Date类日期计算
- UESTC 893 First Date 计算时间
- UESTC 893 First Date 计算时间
- date命令计算日期跨天
- Linux利用date进行日期计算
- JS DATE 计算两个日期之差
- Date(日期类)
- 回文日期(date)
- 日期类(Date)
- First Date
- First Date
- Python日期操作date,计算到特定日期的时间。
- nyoj 219 An problem about date 日期计算 附加最优代码(基姆拉尔森公式)
- (NYoj 219)An problem about date ——日期万能公式(基姆拉尔森计算公式)
- boost准模板库date类使用(续1 date与日期date 周weeks 年份years 天days计算)
- JavaScript Date(日期)对象
- Incircle and Circumcircle(二分+几何)浙大月赛zoj3806(详解版)图
- Beans Game(博弈 | | DP)zoj 3057
- 吉哥系列故事——临时工计划(dp)
- Factorial Problem in Base K(zoj3621)
- Inviting Friends(hdu3244 && zoj3187)完全背包+二分
- First Date (hnoj12952)日期计算
- 11078 - Open Credit System
- Median(vector+二分)
- 对进程地址空间的一点认识
- Cuckoo for Hashing(hash)
- Alice and Bob(博弈)
- 最小公倍数(BNUOJ30195)
- 让面试官“告诉”你,你很出菜
- 省选前Todo List