用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c#代码库

乐学日历

2020-01-08 作者:飞雪举报

[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;  
}


分享到:
更多

网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。