#include<iostream> #include<stdio.h> usingnamespacestd; intmain() { intyear; intmonth; intmonthcodearr[12]={1,4,4,7,2,5,7,3,6,1,4,6}; charweek[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; intday; printf("inputthedate(YYYY-MM-DD)\n"); scanf("%d-%d-%d",&year,&month,&day);//這裡主要是格式化輸入。2011-6-20要按照這個格式輸入。 intyearcode; intmonthcode; if(year>2000) { yearcode=4-2*((year-2000)/4)+(year-2000)%4+1; } elseif(year==2000) { yearcode=4; } else { yearcode=4+2*(2000-year)/4-(2000-year)%4; } monthcode=monthcodearr[month-1]; intweekcode=(yearcode+monthcode+day)%7; cout<<yearcode<<endl; cout<<monthcode<<endl; cout<<day<<endl; cout<<weekcode<<endl; cout<<week[weekcode]<<endl; }
#include<iostream> #include<stdio.h> usingnamespacestd; intmain() { intyear; intmonth; intmonthcodearr[12]={1,4,4,7,2,5,7,3,6,1,4,6}; charweek[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; intday; printf("inputthedate(YYYY-MM-DD)\n"); scanf("%d-%d-%d",&year,&month,&day);//這裡主要是格式化輸入。2011-6-20要按照這個格式輸入。 intyearcode; intmonthcode; if(year>2000) { yearcode=4-2*((year-2000)/4)+(year-2000)%4+1; } elseif(year==2000) { yearcode=4; } else { yearcode=4+2*(2000-year)/4-(2000-year)%4; } monthcode=monthcodearr[month-1]; intweekcode=(yearcode+monthcode+day)%7; cout<<yearcode<<endl; cout<<monthcode<<endl; cout<<day<<endl; cout<<weekcode<<endl; cout<<week[weekcode]<<endl; }