[c#]代码库
#include <stdio.h>
# define shuru(A) if(A<10)printf(" *%d*",A);else printf(" *%d*",A);
int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void jinggong(int a,int b,int c);
int run(int a);
int weekd(int a);
int main (){
int y,m,d,weekday,mday=1,month=1,line=0,i,j=0,k,h,t;
char monthname[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int daya[6][7]={{0}},dayb[6][7]={{0}},dayc[6][7]={{0}};
scanf("%d-%d-%d",&y,&m,&d);
weekday=weekd(y);
if(run(y)==1)monthday[2]=29;
printf("+-----------------------------------------------------------------------------------------+\n");
if(y>3000||y<1000||m<1||m>12||d<0||d>monthday[m]){
jinggong(y,m,d);
return 0;
}
int one,two,three,four;
one=y/1000;two=(y-1000*one)/100;three=(y-1000*one-100*two)/10;four=y-1000*one-100*two-10*three;
printf("| |\n");
printf("| Calendar of Year [ %d %d %d %d ] |\n",one,two,three,four);
printf("| |\n");
for(i=0;i<4;i++){
while(mday<=monthday[month]){
daya[line][weekday%7]=mday;
weekday++;
if(weekday%7==1)line++;
mday++;
}
month++;
mday=1;
line=0;
while(mday<=monthday[month]){
dayb[line][weekday%7]=mday;
weekday++;
if(weekday%7==1)line++;
mday++;
}
month++;
mday=1;
line=0;
while(mday<=monthday[month]){
dayc[line][weekday%7]=mday;
weekday++;
if(weekday%7==1)line++;
mday++;
}
month++;
mday=1;
line=0;
printf("+-----------------------------+-----------------------------+-----------------------------+\n");
printf("| %s | %s | %s |\n",monthname[j],monthname[j+1],monthname[j+2]);
printf("+-----------------------------+-----------------------------+-----------------------------+\n");
printf("| Mon Tue Wed Thu Fri Sat Sun | Mon Tue Wed Thu Fri Sat Sun | Mon Tue Wed Thu Fri Sat Sun |\n");
j=j+3;
for(line=0;line<6;line++){
printf("|");
if(i*3+1==m)t=1;
else t=0;
for(k=1;k<7;k++){
if(daya[line][k]==0){
if(t==1&&daya[line][k-1]==d&&k!=1)printf(" ");
else printf(" ");
}
else if((t==1)&&daya[line][k]==d){
shuru(daya[line][k])
}else if(t==1&&k!=1&&daya[line][k-1]==d)printf("%3d",daya[line][k]);
else printf("%4d",daya[line][k]);
}
if(t==1&&daya[line][0]==0&&daya[line][6]==d)printf(" ");
else if(daya[line][0]==0)printf(" ");
else if(t==1&&daya[line][0]==d)shuru(daya[line][0])
else if(t==1&&daya[line][6]==d)printf("%3d ",daya[line][0]);
else printf("%4d ",daya[line][0]);
printf("|");
if(i*3+2==m)t=1;
else t=0;
for(k=1;k<7;k++){
if(dayb[line][k]==0){
if(t==1&&dayb[line][k-1]==d&&k!=1)printf(" ");
else printf(" ");
}
else if((t==1)&&dayb[line][k]==d){
shuru(dayb[line][k])
}else if(t==1&&k!=1&&dayb[line][k-1]==d)printf("%3d",dayb[line][k]);
else printf("%4d",dayb[line][k]);
}
if(t==1&&dayb[line][0]==0&&dayb[line][6]==d)printf(" ");
else if(dayb[line][0]==0)printf(" ");
else if(t==1&&dayb[line][0]==d)shuru(dayb[line][0])
else if(t==1&&dayb[line][6]==d)printf("%3d ",dayb[line][0]);
else printf("%4d ",dayb[line][0]);
printf("|");
if(i*3+3==m)t=1;
else t=0;
for(k=1;k<7;k++){
if(dayc[line][k]==0){
if(t==1&&dayc[line][k-1]==d&&k!=1)printf(" ");
else printf(" ");
}
else if((t==1)&&dayc[line][k]==d){
shuru(dayc[line][k])
}else if(t==1&&k!=1&&dayc[line][k-1]==d)printf("%3d",dayc[line][k]);
else printf("%4d",dayc[line][k]);
}
if(t==1&&dayc[line][0]==0&&dayc[line][6]==d)printf(" ");
else if(dayc[line][0]==0)printf(" ");
else if(t==1&&dayc[line][0]==d)shuru(dayc[line][0])
else if(t==1&&dayc[line][6]==d)printf("%3d ",dayc[line][0]);
else printf("%4d ",dayc[line][0]);
printf("|");
printf("\n");
}
for(k=0;k<6;k++){
for(h=0;h<7;h++){
daya[k][h]=0;
dayb[k][h]=0;
dayc[k][h]=0;
}
}
line=0;
}
printf("+-----------------------------+-----------------------------+-----------------------------+\n");
jinggong(y,m,d);
}
void jinggong(int a,int b,int c){
printf("| |\n");
if(a>3000||a<1000||b<1||b>12||c<0||c>monthday[b])
printf("| ** |\n");
else
printf("| ** %d-%02d-%02d |\n",a,b,c);
printf("| *** ** |\n");
printf("| *** ** ********* ********** *********** |\n");
printf("| *** **** *** *** *** ** *** ** |\n");
printf("| ** ** **** ***** *** *** *** ** *** * |\n");
printf("| ** *** **** ******** *** *** *** ** *** * |\n");
printf("| ** ** ** ***** ******* *** *** *** *** |\n");
printf("| ******* ** *** *** *** *** *** *** |\n");
printf("| ** ******** ** *** *** *** *** |\n");
printf("| **** ***** ** ******** *** *** |\n");
printf("| ******** *** ** *** *** *** *** |\n");
printf("| ** *** ******** ** *** ** *** *** |\n");
printf("| ****** ** ** ** *** *** *** *** |\n");
printf("| ****** ******* ** *** *** *** *** |\n");
printf("| ** ** ** ** ** *** *** *** *** |\n");
printf("| *** ** ** ** *********** *** *** *** *** |\n");
printf("| ** ** ***** ** ************ ** *** *** *** *** |\n");
printf("| ** ** ** *** **** ********** ********* ***** |\n");
printf("| ** ** *** |\n");
printf("| ** ** ***** |\n");
printf("| ** *** http://online.bit.edu.cn/ |\n");
printf("| ** |\n");
printf("| |\n");
printf("+-----------------------------------------------------------------------------------------+\n");
}
int run(int a){
if((a%4==0&&a%100!=0)||(a%400==0)) return 1;
else return 0;
}
int weekd(int a){
int w;
w=((a-1)*365+(a-1)/4-(a-1)/100+(a-1)/400);
return w%7+1;
}
初级程序员
by: 藤原千花 发表于:2020-04-20 20:28:17 顶(23) | 踩(23) 回复
666
回复评论