天天看点

华师大 OJ 2850

题目描述:点击打开链接

这个是真的简单

解决方案:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int run(int);
void solve(int);

int main()
{
    int year;
    while(scanf("%d",&year)!=EOF){
        printf(" SU MO TU WE TH FR SA\n");
        solve(year);
    }
    return 0;
}


int run(int year){
    if(year != 2100  && (year-2008)%4==0  ){
        return 1;
    }
    else return 0;
}

void solve(int year){
    int record[100];
    int month_days;
    int k,i,diff;
    int space;

    if(run(year) == 1){
        month_days = 29;
    } else  month_days = 28;

    for(k=0;k<=91;k++){
        if(k==0){
            record[k] = 0;
        }else if(k%4==1 && k!=0){
            record[k] = record[k-1] + 366;
        } else record[k] = record[k-1] +365;

    }
    record[92] = record[91] + 365;
    diff = record[year - 2008] % 7;
    space = (5 + diff) % 7;
    for(k=0;k<space;k++){
        printf("   ");
    }
    for(k=1; k<= month_days;k++){
        printf("%3d",k);
        space = (space + 1)%7;
        if(space==0) putchar('\n');
    }
    if(space==0) putchar('\n');
    else printf("\n\n");
}