标签:des style blog io ar color os sp for
2 2013 70 1 2013 3 1 1 2000 3 1
2013/03/11 60 61
我的代码:
1 #include <stdio.h> 2 3 int main() 4 { 5 struct mydata 6 { 7 int year; 8 int month; 9 int day; 10 } date; 11 int days,month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 12 int dyas[13]={0,31,60,91,121,152,182,213,244,274,305,335,366}; 13 int dyas1[13]={0,31,59,90,120,151,181,212,243,273,304,334,365}; 14 int sw,yera,dya,mon=-1,d,i; 15 while(scanf("%d",&sw)!= EOF) 16 { 17 if(1==sw) 18 { 19 days=0; 20 scanf("%d%d%d",&date.year,&date.month,&date.day); 21 int i; 22 for(i=0;i<date.month;i++) 23 days+=month[i]; 24 days+=date.day; 25 if((date.year%4==0&&date.year%100!=0)||(date.year%400==0)) 26 if(date.month>=3) 27 days++; 28 printf("%d\n",days); 29 } 30 if(2==sw) 31 { 32 33 scanf("%d%d",&yera,&dya); 34 if((yera%4==0&&yera%100!=0)||(yera%400==0)) 35 { 36 for(i=0;i<13;i++) 37 { 38 if(dyas[i]>dya) 39 { 40 mon=i; 41 d=dya-dyas[i-1]; 42 break; 43 } 44 else if(dyas[i]==dya) 45 { 46 mon=i; 47 d=month[i]; 48 if(mon==2) 49 d++; 50 break; 51 } 52 } 53 } 54 else 55 { 56 for(i=0;i<13;i++) 57 { 58 if(dyas1[i]>dya) 59 { 60 mon=i; 61 d=dya-dyas1[i-1]; 62 break; 63 } 64 else if(dyas1[i]==dya) 65 { 66 mon=i; 67 d=month[i]; 68 break; 69 } 70 } 71 72 } 73 printf("%04d/%02d/%02d\n",yera,mon,d); 74 } 75 76 } 77 78 return 1; 79 }
其他代码:
1 #include <iostream> 2 3 using namespace std; 4 int isRN(int y) 5 { 6 if((y%4==0&&y%100!=0)||y%400==0) 7 { 8 return 1; 9 } 10 return 0; 11 } 12 int a[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; 13 int main() 14 { 15 int n; 16 int y,m,d; 17 int s; 18 int flag; 19 while(cin>>n) 20 { 21 22 s=0; 23 if(n==1) 24 { 25 cin>>y>>m>>d; 26 flag=isRN(y); 27 for(int i=1;i<m;++i) 28 { 29 s+=a[flag][i]; 30 } 31 s+=d; 32 cout<<s<<endl; 33 } 34 else if(n==2) 35 { 36 cin>>y>>s; 37 flag=isRN(y); 38 m=0; 39 do{ 40 s-=a[flag][++m]; 41 }while(s>0); 42 d = s+a[flag][m]; 43 if(m>=10) 44 { 45 cout<<y<<"/"<<m<<"/"<<d<<endl; 46 } 47 else 48 { 49 cout<<y<<"/0"<<m<<"/"<<d<<endl; 50 51 } 52 53 } 54 55 56 } 57 return 0; 58 }
武汉科技大学ACM :1010: 华科版C语言程序设计教程(第二版)例题7.8
标签:des style blog io ar color os sp for
原文地址:http://www.cnblogs.com/liuwt365/p/4147432.html