思路:利用Switch没有braek的下滑的特性完成计算
#include <stdio.h> int main(){ int sum=0; int month,day,year; scanf("%d%d%d",&year,&month,&day); switch(month){ ?? ?case 12: ?? ??? ?sum+=30; ?? ?case 11: ?? ??? ?sum+=31; ?? ?case 10: ?? ??? ?sum+=30; ?? ?case 9: ?? ??? ?sum+=31; ?? ?case 8: ?? ??? ?sum+=31; ?? ?case 7: ?? ??? ?sum+=30; ?? ?case 6: ?? ??? ?sum+=31; ?? ?case 5: ?? ??? ?sum+=30; ?? ?case 4: ?? ??? ?sum+=31; ?? ?case 3: ?? ??? ?sum+=28; ?? ?case 2: ?? ??? ?sum+=31; ?? ?case 1: ?? ??? ?sum+=0; } if(month>=3&&year%4==0&&year%400!=0){ ?? ?sum+=1; } sum+=day; printf("%d",sum); return 0;? }
|