计算所给日期为该年的第几天
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 int main() 6 { 7 int y,m,d; 8 int mm; 9 char c; 10 int date; 11 while (scanf("%d",&y)!=EOF) 12 { 13 date=0; 14 scanf("%c%d%c%d",&c,&m,&c,&d); 15 mm=m; 16 while (m--) 17 { 18 switch(m) 19 { 20 case 12:date+=31; break; 21 case 11:date+=30; break; 22 case 10:date+=31; break; 23 case 9: date+=30; break; 24 case 8: date+=31; break; 25 case 7: date+=31; break; 26 case 6: date+=30; break; 27 case 5: date+=31; break; 28 case 4: date+=30; break; 29 case 3: date+=31; break; 30 case 2: date+=28; break; 31 case 1: date+=31; break; 32 } 33 } 34 if (((0==y%4&&y%100!=0)||(0==y%400))&&(mm>2)) date++; 35 date+=d; 36 printf("%d ",date); 37 } 38 return 0; 39 }