#include<stdio.h> int all[13]={0,31,60,91,121,152,182,213,244,274,305,335,366}; int main() { int y,m,d; scanf("%d %d %d",&y,&m,&d); if((y%4==0&&y%100!=0)||(y%400==0)){ for(int i=0;i<13;i++) all[i]=all[i]; } else{ for(int i=2;i<13;i++)all[i]-=1; } printf("%d",all[m-1]+d); return 0; }
二月份是特殊值,注意这个就好了。
int leapyear(int n); int main(){ int mouths[13]={31,28,31,30,31,30,31,31,30,31,30,31}; int year,mouth,day; int sum=0; scanf(“%d %d %d”,&year,&mouth,&day); if(leapyear(year)){ mouths[1]=29; } for(int i=0;i<mouth-1;i++){ sum+=mouths[i]; } sum+=day; printf(“%d”,sum); return 0; } int leapyear(int n) { int res=0; if(n%400==0)res=1; else if(n%4==0){ if(n%100==0)res=0; else res=1; } return res; }
#include<stdio.h> int all[13]={0,31,60,91,121,152,182,213,244,274,305,335,366}; int main() { int y,m,d; scanf("%d %d %d",&y,&m,&d); if((y%4==0&&y%100!=0)||(y%400==0)){ for(int i=0;i<13;i++) all[i]=all[i]; } else{ for(int i=2;i<13;i++)all[i]-=1; } printf("%d",all[m-1]+d); return 0; }
二月份是特殊值,注意这个就好了。
include
int leapyear(int n);
int main(){
int mouths[13]={31,28,31,30,31,30,31,31,30,31,30,31};
int year,mouth,day;
int sum=0;
scanf(“%d %d %d”,&year,&mouth,&day);
if(leapyear(year)){
mouths[1]=29;
}
for(int i=0;i<mouth-1;i++){
sum+=mouths[i];
}
sum+=day;
printf(“%d”,sum);
return 0;
}
int leapyear(int n)
{
int res=0;
if(n%400==0)res=1;
else if(n%4==0){
if(n%100==0)res=0;
else res=1;
}
return res;
}