zcmu-2119
2119: 任意年月日歷
Time Limit:?1 Sec??Memory Limit:?128 MBSubmit:?67??Solved:?18
[Submit][Status][Web Board]
Description
已知2007年1月1日為星期一。
設計一函數按照下述格式打印2007年以后(含)某年某月的日歷,2007年以前的拒絕打印。
為完成此函數,設計必要的輔助函數可能也是必要的。其中輸入為年分和月份。
Input
Output
Sample Input
Sample Output
Calendar 2007-01--------------------- Su Mo Tu We Th Fr Sa--------------------- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31---------------------HINT
Source
算法提高
求輸出的某年的日歷,順便說一下,這題你不遇到presentation erro的話,就牛逼了? ?6次的presentation Error,最后
改了自己手寫的算天數的代碼,取消了引用公式就對了
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<set> #include<map> #include<stack> #include<list> using namespace std;int y,m;int leapYear(int y) {if((y%4==0&&y%100!=0)||y%400==0)return 1;return 0; }int main() {while(~scanf("%d %d",&y,&m)){int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};if(y<2007)break;int d=1;if(leapYear(y)){a[2]=29;}for(int i=0; i<m; i++)d+=a[i]; // int t=(y-1)+(y-1)/4+(y-1)/400-(y-1)/100+d;//公式,不知道為什么用了卻不對 // t%=7;int w = 1;//以下是自己寫的求某個月的第一天是星期幾的代碼for ( int i=2007 ; i<y ; i++ )if ( leapYear(i) ) w = (w+366)%7;else w = (w+365)%7; for ( int i=1 ; i<m ; i++ )w = (w+a[i])%7;//printf("Calendar %d-%02d\n",y,m);puts("---------------------");puts(" Su Mo Tu We Th Fr Sa");puts("---------------------");for(int i=0; i<w; i++){printf(" ");}int k=w;for(int i=1; i<=a[m]; i++){if(k==7){k=0;puts("");}printf("%3d",i);k++;}puts("\n---------------------");}return 0; }與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
- 上一篇: Named服务配置
- 下一篇: zcmu-2116一元三次方程求解