标签:des style blog http color os io java ar
Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1751 Accepted Submission(s): 628
1 #include<stdio.h> 2 #include<string.h> 3 int reyue []={0,31,29,31,30,31,30,31,31,30,31,30,31}; 4 int noyue []={0,31,28,31,30,31,30,31,31,30,31,30,31}; 5 bool Isy(int n){ 6 if((n%4==0&&n%100!=0)||n%400==0)return 1; 7 return 0; 8 } 9 void nday(int da){ 10 int year=2013,yue=1,day=1; 11 int pn=2013,py=12,pd=31; 12 int d=da+82; 13 while(d>=365){ 14 if(Isy(year)) d-=366; 15 else d-=365; 16 if(d>=0)year++; 17 } 18 if(d==-1) yue=12,day=31; 19 else 20 if(Isy(year)) 21 while(d>=reyue[yue]) d-=reyue[yue++]; 22 else 23 while(d>=noyue[yue]) d-=noyue[yue++]; 24 day+=d; 25 d=da+282; 26 while(d>365){ 27 if(Isy(pn)) d-=366; 28 else d-=365; 29 pn--; 30 } 31 if(Isy(pn)){ 32 while(d>reyue[py]) d-=reyue[py--]; 33 pd=reyue[py]-d; 34 } 35 else{ 36 while(d>noyue[py]) d-=noyue[py--]; 37 pd=noyue[py]-d; 38 } 39 if(pd==0){ 40 py--; 41 if(py==0) pn--,py=12,pd=31; 42 else if(Isy(pn)) pd=reyue[py]; 43 else pd=noyue[py]; 44 } 45 printf("%04d/%02d/%02d %04d/%02d/%02d\n",year,yue,day,pn,py,pd); 46 } 47 int main(){ 48 int d,cas; 49 scanf("%d",&cas); 50 while(cas--){ 51 scanf("%d",&d); 52 nday(d); 53 } 54 return 0; 55 }
然后进过一系列的优化美观之后:
1 #include<stdio.h> 2 #include<string.h> 3 int ryue [2][13]={{365,31,28,31,30,31,30,31,31,30,31,30,31}, 4 {366,31,29,31,30,31,30,31,31,30,31,30,31}}; 5 int Isy(int n){ 6 if((n%4==0&&n%100!=0)||n%400==0)return 1; 7 return 0; 8 } 9 struct Time{ 10 int year,mon,day; 11 }; 12 void nday(int da){ 13 Time t1={2013,1,1},t2={2013,12,31}; 14 int d=da+82; 15 while(d>=365){ 16 d-=ryue[Isy(t1.year)][0]; 17 if(d>=0)t1.year++; 18 } 19 if(d==-1) t1.mon=12,t1.day=31; 20 else 21 while(d>=ryue[Isy(t1.year)][t1.mon]) d-=ryue[Isy(t1.year)][t1.mon++]; 22 t1.day+=d; 23 d=da+282; 24 while(d>365){ 25 d-=ryue[Isy(t2.year)][0]; 26 t2.year--; 27 } 28 while(d>ryue[Isy(t2.year)][t2.mon]) d-=ryue[Isy(t2.year)][t2.mon--]; 29 t2.day=ryue[Isy(t2.year)][t2.mon]-d; 30 if(t2.day==0){ 31 t2.mon--; 32 if(t2.mon==0) t2.year--,t2.mon=12,t2.mon=31; 33 else t2.day=ryue[Isy(t2.year)][t2.mon]; 34 } 35 printf("%04d/%02d/%02d %04d/%02d/%02d\n",t1.year,t1.mon,t1.day,t2.year,t2.mon,t2.day); 36 } 37 int main(){ 38 int d,cas; 39 scanf("%d",&cas); 40 while(cas--){ 41 scanf("%d",&d); 42 nday(d); 43 } 44 return 0; 45 }
hdu---(4515)小Q系列故事——世界上最遥远的距离(模拟题)
标签:des style blog http color os io java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3960124.html